4

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?

Draco Ater
  • 20,820
  • 8
  • 62
  • 86

6 Answers6

2

As already mentioned, this is not possible. Also, it is not possible to set a property for the parent's version as the interpolation for that happens a lot earlier than the handling of the profiles.

I would suggest that you create a masterbuild project as follows:

master
|-plugin-jenkins
|-plugin-hudson
|-plugin-assembly

The master should build all three as usual. However, in the assembly, you could add each of the two plugins as dependencies in separate profiles. And... each of these plugins can have the parent you like.

This is obviously somewhat a deviation from the Maven convention, but I believe it is a solution to your problem.

carlspring
  • 31,231
  • 29
  • 115
  • 197
  • Thanks, I will try it. But this way I have to have 2 copies of my code: in plugin-jenkins and in plugin-hudson. Can it somehow be done so, that I build hudson based on jenkins code or vice versa? – Draco Ater Jun 29 '11 at 12:28
  • Well, I would actually suggest that you have two separate projects for the packaging of this (at least). As Karl-Heinz pointed out below, Hudson and Jenkins have parted ways and it's likely that things that now (still) work will not work in the near future. You could keep most of the code in a core module and then have the Hudson or Jenkins-specific stuff in the packaging module (which depends on the core). Something along these lines should solve your problem. – carlspring Jun 29 '11 at 12:32
1

It's not possible because the tag "parent" is not available in the profiles section of the pom.

Jan
  • 930
  • 9
  • 25
1

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
Draco Ater
  • 20,820
  • 8
  • 62
  • 86
0

In general, you should be able to set the {group,artifact}Id and version of the parent POM via Java System Properties or Environment Variables, but it seems there is a Bug in Maven which will only be fixed in 4.x: https://issues.apache.org/jira/browse/MNG-624

Another solution is to delegate the inclusion of the parent POM to your own parent POMs which you reference in the relativePath element, and change the content of the target e.g. via a symlink or cp command.

So in the main POM you would write:

<parent>
    <groupId>org.mycompany.project</groupId>
    <artifactId>foo-artifact</artifactId>
    <version>1.0.0</version>
    <relativePath>./my-parent.pom</relativePath>
</parent>

And in my-parent-jenkins you would just put:

<groupId>org.mycompany.project</groupId>
<artifactId>foo-artifact</artifactId>
<version>1.0.0</version>

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

The same project information with the block for hudson you put in my-parent-hudson.pom.

No you can either use

ln -s my-parent-jenkins.pom my-parent.pom

or

ln -s my-parent-hudson.pom  my-parent.pom

to include the respective parent POM without the need to maintain two different main POM files for your project.

In case POM does not exist at the place referenced in relativePath, Maven will look up the POM in the remote repository[1], which is also an easy way to overwrite a parent POM locally.

[1] http://maven.apache.org/components/ref/3.3.9/maven-model/maven.html#class_parent

red_hood
  • 61
  • 1
  • 3
0

No you cannot do that. you will have to refactor somehow to avoid the necessity.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
0

As mentioned already not possible. I would suggest to make separate projects for jenkins plugin and hudson plugin. I assume that in not that far future that will not work anymore cause Hudons and Jenkins will diverge.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235