mavenpom.xmlprofiles

Maven: Selecting Parent Project Based On Profile


I have a maven project - it is a plugin for jenkins. It's parent should be a:

<parent>
  <groupId>org.jenkins-ci.plugins</groupId>
  <artifactId>plugin</artifactId>
  <version>1.414</version>
</parent>

But at the same time this plugin can be also used for hudson, without changing any line of code. But the parent project for it should be:

<parent>
  <groupId>org.jvnet.hudson.plugins</groupId>
  <artifactId>hudson-plugin-parent</artifactId>
  <version>2.0.1</version>
</parent>

Can I specify 2 different profiles for that and use them to build plugin for jenkins or hudson accordingly? So that I call something like that:

mvn package -P jenkins

or

mvn package -P hudson

I have tried to specify properties in profiles, but those are not replaced by their values inside the <parent> tag. So is there any other possibility to build plugin for both, but with as much as possible common code and files?

Added: So, if I cannot do that, what should I do then? How to refactor? What the new structure should be?


Solution

  • Currently we decided to stick with 1 repository and 2 separate pom.xml files, giving maven key which pom.xml use to build the project.

    mvn package -f pom-jenkins.xml
    mvn package -f pom-hudson.xml