How to activate a Maven profile per pom.xml?

前端 未结 3 1929
后悔当初
后悔当初 2021-01-27 02:39

I have a large Maven project with one master module and lots of children, organized in a nice tree structure. However, some of the modules need special settings which would caus

相关标签:
3条回答
  • 2021-01-27 03:06

    Don't use profile, Mateusz Balbus answer, that is define nested pom-packaged project that define java and scala modules respectively

    0 讨论(0)
  • 2021-01-27 03:14

    If you want to configure maven profile for each project(module) then you have to add profile setting in the project(module) pom.xml file

    <profiles>
      <profile>
        <activation>
          <jdk>1.4</jdk>
        </activation>
        <your properties goes here>
      </profile>
    </profiles>
    

    Also if you do not want to execute some profile then you have to add

        mvn groupId:artifactId:goal -P !profile-1,!profile-2
    

    in the project pom.xml file

    0 讨论(0)
  • 2021-01-27 03:18

    As far as I understood you want to activate profile from child pom based on its configuration. I'm afraid it is not possible. However you can reorganize project tree structure to take advantage of pom inheritance: pom.xml // general properties for all projects |-- java-modules | -- pom.xml // inherits from master pom, configures maven-compile-plugin | -- java-8-modules | -- pom.xml // inherits from java-modules pom, uses java 8 compiler | -- java-8-project-a | -- java-7-modules | -- pom.xml // inherits from java-modules pom, uses java 7 compiler | -- java-7-project-a |-- scala-modules -- pom.xml // inherits from master pom, configures maven-scala-plugin -- scala-project-a You write one master pom for all modules in top directory, child poms just specify java/scala details.

    More about pom inheritance https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance

    0 讨论(0)
提交回复
热议问题