Building same project in Maven with different artifactid (based on JDK used)

后端 未结 5 689
悲哀的现实
悲哀的现实 2020-12-01 12:05

I have a scenario wherein my project needs to be compiled in different JDKs and the resulting artifact name should be different based on the JDK used. For example if the pro

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 12:56

    What you can do is to define two profiles, one per JDK used. Each profile will be activated regarding which JDK is used:

    
        
            profile-for-jdk1.4
            
                false
                1.4
            
            
                myBuild-jdk1.4
            
        
        
            profile-for-jdk1.5
            
                false
                1.5
            
            
                myBuild-jdk1.5
            
        
    
    

    Then, in each profile, you define a specific , which will be used to name the generated JAR file.

    Thus, if you build your application using JDK 1.4, the generated JAR will be named myBuild-jdk1.4.jar.

    If your final package is built using an assembly, you can simply change the block inside profiles to configure the assembly plugin (for example to ).


    Regarding your comment: Indeed, this procedure will need two separate builds on Maven, as you have to recompile the whole project when changing the JDK version. One of the Maven2 convention is that one project = one artifact. What you want is to have one project with two artifacts.

    Eventually, one solution is to use Hudson to build your application, and especially the matrix feature of this tool, which allows you to run multiple builds with various parameters, in your case the JDK.

提交回复
热议问题