Maven artifacts for multiple environments

I am working on a project that uses Maven for build and Artifactory as Maven repository where the build is published. All works fine when there is just one set of configuration - build is created and published to Artifactory.

I need to be able to create a single WAR that contains necessary binaries and one additional artifact for each environment that contains environment specific resources (MongoDB connection URL and log4j2 xml). Deployment job in Jenkins should deploy WAR and environment specific resource JAR to the server.

I am stuck in creating and publishing artifacts. Approaches I tried and rejects are:

  • Maven profiles - rejected as it creates a separate WAR file for each environment. I find it illogical to create WAR files of few tens of MBs just to change few configurations.
  • Spring profiles - rejected as it uses code to solve deployment problem by deploying all configurations on all servers and relying on setting profile in environment + code change to read based on configured profile name.
  • Maven resources plugin - can be used to copy environment specific resources in appropriate directory structure; but does not get published to Artifactory during "deploy" phase.
  • Maven Jar plugin - can create attached JAR artifact, but attached artifacts cannot contain resource (or at least I could not figure out a way to include resources in attached JAR)
  • Maven build helper plugin - can publish individual files as attached artifacts, but file names are changed when deploying to Artifactory.
  • Multimodule POM - this approach could work to create resource artifact for each environment but has 2 disadvantages:
  • Updating version of main artifact needs update to all POMs (easy to miss out)
  • Not scalable - need to create separate POM if new environment is added.
  • It seems that Maven + Artifactory is not geared towards multi-environment scenario as there simply does not seem to be any straightforward solution. Am I missing something? What approach should I take?

    Update I solved the problem by using https://github.com/khmarbaise/multienv-maven-plugin. This lets me create one WAR and multiple JAR files: - myapp.0.1.0.war - myapp.0.1.0-dev.jar - myapp.0.1.0-qa.jar - myapp.0.1.0-prod.jar

    I am stuck at next step. Install phase installs the JARs as WARs and subsequently Deploy phase uploads them to Artifactory as WARs. Any way to keep packaging type as JAR for the JARs?

    链接地址: http://www.djcxy.com/p/79984.html

    上一篇: Heroku预编译资产在Rail 4应用程序上失败

    下一篇: 适用于多种环境的Maven工件