Have maven list (transitively) inherited parent POMs? - maven

Is there an easy way to make maven list the parent POMs a POM inherits directly and indirectly?
I'm looking for something similar to
mvn dependency:tree
only "upstream" (i.e. for parent POMs inherited), not "downstream" (i.e. for dependencies on other libraries)...

I wanted to print the version of our corporate parent POMs. I used the GMaven plugin for this, as described in this stackoverflow answer. You could modify that code bit to print each parent POM.

I don't know a Maven command to do this. If you use Eclipse and the m2e plugin, then you can press F3 inside of the <parent> element to visit the parent POM. Then rinse and repeat.

Related

Dependency Management in AEM project POMs

In AEM project poms I have noticed that dependency name and versions are defined in the parent pom and it is not necessary to specify a version in child poms, as the version is managed at the Parent pom. And child poms only have dependencies defined. So, I am not clear on following.
1.If we already have dependencies defined in the parent pom with version no, then why do we need to define the same dependency back in child pom.xml (core/pom.xml in case of AEM).
In Maven there is a difference between <dependencies> and <dependencyManagement>. Only the former really adds dependencies to your project, while the latter only defines the preferred version numbers (and scopes).

POM references a dependency and a parent the same way. How we choose what is what?

I found that syntax of parent and dependency references in POM are practically the same:
<parent>
<groupId>com.topdesk</groupId>
<artifactId>tis-parent</artifactId>
<version>3.4</version>
</parent>
Dependency has the same inner content. Why we choose to put something as parent instead of using dependency?
These are different concepts. Referencing a parent makes Maven look for a pom from which it inherits (using all the plugin definitions, profiles, declared dependencyManagement etc.), i.e. the parent and your pom are put together as one and executed.
Using a dependency means that Maven looks for a jar (unless you explicitly tell it to look for a pom, which essentially means that it adds all dependencies from that pom as transitive dependencies). This jar is put on the classpath (together with its dependency tree).

Which Pom is parent?

In a maven project which pom.xml is the parent pom? And is that the one I need to change in order to add a profile?
I have a simple project and am trying to add a profile to download from a specific repository but nothing's seems to be working.
I assume you have a multi-module build.
Parent relationship is optional between poms, and specified with the <parent> tag inside the pom.
You may point to a single pom, but if not, you point to a default super-pom.
Use mvn help:effective-pom to shed some light on your settings.
If you have a shared pom file, you can add profiles to that one, otherwise you need to include them in each pom.
Use mvn help:active-profiles to see which ones are enabled.
For ref: http://maven.apache.org/guides/introduction/introduction-to-profiles.html

maven skip/ignore parent tag

I wonder if it is possible to ignore parent tag in the pom.xml file. I need this because I have the following situation:
the structure is:
super root pom
root pom
module1 pom
module2 pom
module2.1 pom
module2.2 pom
module2.3 pom
I need to set super root pom as parent pom for root pom to make it availible to build it specifically on build server, but the trick is, that I don't have super root pom locally and need to ignore parent tag or do something not to be dependent on super parent pom. So, for example, I need to run root pom clean install independently from the super root pom. Is there any way to do this using some parameters or some pom.xml tricks?
Thanks everyone in advance!
If you have a corporate repo (Nexus, Artifactory...) The simpler would be to mvn deploy your parent, to make it available for all your projects, all your team, with no need of a local (relative file system path) relationship.

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?
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.
It's not possible because the tag "parent" is not available in the profiles section of the pom.
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
No you cannot do that. you will have to refactor somehow to avoid the necessity.
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.
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

Resources