Release different configurations with Maven

后端 未结 4 1760
花落未央
花落未央 2020-12-07 05:27

I\'m currently migrating our build process to Maven from Ant. Our application is deployed to many different customers, each with a unique set of dependencies and and configu

4条回答
  •  萌比男神i
    2020-12-07 05:53

    "declare several execution for the war plugin to produce several artifacts (and install/deploy them)" This sounds like this might be the way forward. How would I go about doing this?

    This goes a bit against a Maven golden rule (the one main artifact per module rule) but can be done. The One artifact with multiple configurations in Maven blog post describes one way to implement this approach:

    I decided to put all the environment specific configuration in a special source tree, with the following structure:

    +-src/
      +-env/
        +-dev/
        +-test/
        +-prod/
    

    Then I configured the maven-war-plugin to have three different executions (the default plus two extra), one for each environment, producing three different war files: beer-1.0-dev.war, beer-1.0-test.war and beer-1.0-prod.war. Each of these configurations used the standard output files from the project and then copied the content from the corresponding src/env/ directory on to the output files, enabling an override file to be placed in the corresponding src/env/ directory. It also supported copying a full tree structure into the output directory. Thus if you for instance wanted to replace the web.xml in test you simply created the following directory:

    src/env/test/WEB-INF/
    

    and placed your test specific web.xml in this directory and if you wanted to override a db.property file placed in the classpath root directory for the test environment you created the following directory:

    src/env/test/WEB-INF/classes
    

    and placed your test specific db.property file in this directory.

    I kept the src/main directory configured for development environment. The reason for this was to be able to use the maven-jetty-plugin without any extra configuration. Configuration

    Below you find the maven-war-plugin configuration that I used to accomplish this:

    
      maven-war-plugin
      
        prod
        ${project.build.directory}/${project.build.finalName}-prod
        
          
            src/env/prod
          
        
      
      
        
          package-test
          package
          
            test
            ${project.build.directory}/${project.build.finalName}-test
            
              
                src/env/test
              
            
          
          
            war
          
        
        
          package-dev
          package
          
            dev
            ${project.build.directory}/${project.build.finalName}-dev
            
              
                src/env/dev
              
            
          
          
            war
          
        
      
    
    

    (...) I can define each customer project with profiles but I don't know if there's a way to release them to a repository.

    You have several options:

    • use profiles and run the build several times (create artifacts with a classifier and install/deploy them)
    • declare several execution for the war plugin to produce several artifacts (and install/deploy them)
    • use different modules (and maybe war overlays to merge a common part with a specific one)

    Or at least a way in Maven to automatically build an artifact with a specified profile from say an SVN tag.

    Well, this is doable. But without more details about a particular problem, it's hard to be more precise.

提交回复
热议问题