Activate different Maven profiles depending on current module?

前端 未结 6 1145
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 04:05

We have a multi module build with modules using different technologies, like Java and Flex. Is it somehow possible to activate different profiles based on the module that is

相关标签:
6条回答
  • 2020-12-20 04:29

    With regard to file-based activation, you can try removing ${basedir}. We use it like this:

    <activation>
       <file>
          <missing>target/jboss/conf/jboss-service.xml</missing>
       </file>
    </activation>
    
    0 讨论(0)
  • 2020-12-20 04:33

    For those like myself reading this question looking for answers, this use case now works in Maven 3.

    There is was a bug affecting this feature in early versions of 3 (see http://jira.codehaus.org/browse/MNG-2363) but it works for me correctly using Maven 3.0.4.

    0 讨论(0)
  • 2020-12-20 04:34

    After some more research I finally came to the conclusion that this is not possible for two reasons in the current Maven version (2.1.0):

    • Maven profiles are not inherited, so you can't define a profile in a parent POM and activate that in a child POM.
    • I haven't found a possibility to activate a profile from a POM itself. The activation does not work with ${basedir} and the property activation response only to system settings, which are globally specified through the -D option.
    0 讨论(0)
  • 2020-12-20 04:34

    You can set a property in each module that you want to use the profile, and then use "property" activation in your profiles.

    0 讨论(0)
  • 2020-12-20 04:40

    In 2.2.1, profiles are inherited but the ${basedir} issue is still there. I'm in the same boat - I need to activate a profile based on the existence of a file in a given project. My child builds run individually just fine (inherited profile activated by local file existance), but if I run the build from the top parent, they fail because the file isn't found.

    0 讨论(0)
  • 2020-12-20 04:46

    I dont know if this helps, but I solved a similar problem with the following approach:

    1. I created and described the profile in the parent POM, which has activeByDefault=false. The PluginManagement-Section then contains the configurations for different plugins.
    2. The children can reuse this profile, and set activeByDefault=true This makes the profile active, but still none of the plugins are activated.
    3. But fortunately the described plugin configurations are available. You can reuse them in children by defining them in the Plugins-Section. You just provide the group- and the artifactID, and set inherited=true for each plugin you want to reuse in the children.

    I hope that helps. Sorry for not including any code snippets, but I hope even so the soutions is understandable.

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