I don't know if I'm missing something, but I have a problem with the Codehaus versions plugin for Maven. Here's a simplification of my situation:
root:
moduleA
moduleB
'root' is an aggregator POM, i.e. declaring moduleA and moduleB as child modules, and A and B both have root as parent.
Both A and B have a dependency on project-C, but the version of this dependency is defined in a property - say <project-C.version> - not hardcoded. This property is defined in root, so both A and B inherit the same version value for project-C.
In root POM:
<properties>
<project-C.version>1.0</project-C.version>
In module A and B (remember root is parent):
<dependency>
<groupId>com.blah</groupId>
<artifactId>project-C</artifactId>
<version>${project-C.version}</version>
</dependency>
Now, say newer version 1.1-SNAPSHOT of project-C becomes available. I want to use the versions plugin to show this to me, so I run:
$ cd /projects/root
$ mvn versions:display-property-updates -DallowSnapshots=true
but all I get is something like this:
[INFO] Building root
[INFO] This project does not have any properties associated with versions
[INFO] Building moduleA
[INFO] This project does not have any properties associated with versions
[INFO] Building moduleB
[INFO] This project does not have any properties associated with versions
It doesn't make a difference if I run it on root, moduleA or moduleB: it always says that. Of course it works if I hardcode project-C's version number in the dependencies.
So, in summary: I want to centralise dependency versions as properties in a root (aggregator/parent) POM, and I want the versions plugin to pick those up for goals that work on properties, i.e.:
display-property-updates
update-properties
How do I do this? Am I missing something? Is this a bug in versions plugin?
It looks like the answer you received in MVERSIONS-123 is not accurate:
If the properties are defined in the parent pom, then run the goal from the parent pom (including the child projects as part of the aggregator if necessary in order to pick up the dependencies)
This part is not true, or at least doesn't occur. It seems the versions plugin only look or properties in the current pom. Declaring the following in the parent does work:
<properties>
<project-C.version>1.0</project-C.version>
</properties>
<dependencies>
<dependency>
<groupId>com.blah</groupId>
<artifactId>project-C</artifactId>
<version>${project-C.version}</version>
</dependency>
</dependencies>
But declaring the property in the parent and the dependency in the child doesn't (even when running the plugin on the parent).
Now, if the behavior described by Stephen in MVERSIONS-123 is the expected behavior, then there is a bug (and you should actually provide a simple project allowing to reproduce, I did a simple test with Junit as dependency).
But in your case (it was maybe just an example though) since both A and B depend on C, why don't you put C in the parent? This would work. You should use dependencyManagement anyway (and this will work if you don't want to inherit it everywhere).
This seemed to be a job for dependencyManagement section in your root pom...
Related
I'm doing some scripting and I need to get a list of all the parent poms for any given pom. The dependency plugin seems to be only interested in the dependencies that are listed in the dependency section of the pom, but there doesn't seem to be a way to show the parent poms, which are also required dependencies for Maven to work.
Am I missing something basic?
There is no simple Maven command that will show you the chain of parent POMs for a pom.xml. The reason for this is that it is not a common question one would typically ask (more on that below). For your script, you'll just have to parse the pom.xml file, get the parent artifact coordinates, get a hold of the artifact's pom.xml file and then parse it's pom.xml file (and repeat). Sorry, but there is no short cut I know of, but other folks have solved similar problems.
You are right that technically the parent pom is a dependency of your project, but it is not a literal Maven Dependency and is handled completely differently. The chain of parent poms, along with active profiles, your settings.xml file, and the Maven super pom from the installation directory are all combined together to create your project's effective pom. The effective POM is what Maven really uses to do its work. So basically, the parent pom inheritance chain is already resolved and combined before the dependency plugin (or any other plugin) is even activated.
The questions most people typically ask is 'what does my REAL pom.xml really look like when Maven is done combining everything?' or 'What is the result my inheritance chain of parent poms?' or 'How are my pom.xml properties affected by an active profile?' The effective pom will tell you all of this.
I know you didn't ask, but for others reading this, if you want to see your parent pom.xml, simply open up the pom.xml in the M2Eclipse POM editor and click on the parent artifact link on the overview tab. In this way you can quickly move up the chain of pom.xml files with just a single click per pom. It would be a strange project that had more than 3 or 4 parent poms of inheritance.
If you want to see your effective pom, you can run the command mvn help:effective-pom. Alternatively, you can click on the Effective POM tab in M2Eclipse's POM editor.
Basic solution
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1:display-ancestors
If your project defines version 3.1 or later you can use:
mvn dependency:display-ancestors
The output looks similar to:
[INFO] Ancestor POMs: org.springframework.boot:spring-boot-starter-parent:1.4.0.RELEASE <- org.springframework.boot:spring-boot-dependencies:1.4.0.RELEASE
Improved solution
The hierarchy-maven-plugin (that I wrote) can display additional information about imported poms like this :
[INFO] Displaying hierarchy. Set level=full to display dependencies in dependencyManagement
[INFO] PARENT org.springframework.boot:spring-boot-samples:1.4.1.BUILD-SNAPSHOT
[INFO] PARENT org.springframework.boot:spring-boot-starter-parent:1.4.1.BUILD-SNAPSHOT
[INFO] PARENT org.springframework.boot:spring-boot-dependencies:1.4.1.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework:spring-framework-bom:4.3.3.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework.data:spring-data-releasetrain:Hopper-BUILD-SNAPSHOT
[INFO] PARENT org.springframework.data.build:spring-data-build:1.8.4.BUILD-SNAPSHOT
[INFO] IMPORT org.springframework.integration:spring-integration-bom:4.3.1.RELEASE
[INFO] IMPORT org.springframework.security:spring-security-bom:4.1.3.RELEASE
Details are here : https://github.com/ExampleDriven/hierarchy-maven-plugin
I have a library which I "mavenized" recently and put into a local git repository.
In order to lock some plugin versions I created a simple parent pom which defines the plugin versions via pluginManagement (the parent pom file is not checked into any SCM repository). I specify the parent pom in my libraries pom file:
<parent>
<groupId>org.my.company</groupId>
<artifactId>superpom</artifactId>
<version>1</version>
</parent>
I use default directory structure.
When I try to perform a release using the release plugin I run into a problem.
mvn release:prepare runs fine however when I run mvn release:perform maven checks out the corresponding tag from my local git repository into the target/checkout folder and tries to run the deploy goal.
However the build fails with the error message that it can't find the parent pom file defined in my library pom file.
I assume that's related to the fact that maven tries to find the parent pom file in the target folder and it is not available there.
Is there an easy way how to solve this problem?
Update:
I have multiple unrelated GWT libraries which should share the common company parent pom file in order to specify plugin versions.
The parent pom is just used for defining some default versions and won't contain any module definitions because all GWT libraries are unrelated.
The GWT library are really simple and have no real dependencies to any other libraries apart from the default ones (gwt, junit)
Update2:
I solved the problem by installing the superpom into my local repository by running mvn install in the folder of my superpom.
The first fail you did is not to versionise the parent pom where you defined the pluginManagement area. This is the first step you must do put the pom.xml which you like to use a parent. Secondly you have to put the information about the VCS into the scm area of that pom. After you cleaned up everything you must do a mvn release:prepare release:perform of the parent pom. After that you are able to use it as a parent in your other projects. Furthermore you should define the distributionManagement area in your parent pom.
I use a project layout like the first one described in the accepted answer to this question. If my parent-pom is managed, built and deployed separate from my project POMs, how can I ensure the pluginManagement section of my parent-pom is valid?
Maven only checks plugins that actually get used in the build as far as I can tell. Since most of the plugins I'm declaring in pluginManagement don't get used when I build the parent-pom, I have no way of knowing if I have an invalid entry until a child project tries to use a plugin it expects to be managed by the parent-pom.
I've tried the versions plugin, but it seems to ignore plugins that don't exist (ex: typos). I've tried declaring the plugins in my parent-pom with inherited=false, but then I have to tie every declared plugin to a phase. Plus, I don't necessarily want to run those plugins against my parent-pom.
I know lots of people use a parent-pom or a super-pom of some type, so there has to be something I'm overlooking.
In your parent pom module create a set of test maven projects, all inheriting parent pom, using some or all of the plugins defined there, and have parent pom run and verify build success of test maven projects. maven-invoker-plugin can help you in accomplishing all this. This plugin is used a lot for testing maven core plugins so you can find more usage examples in sources of maven core plugins.
Another advice is to add plugins to parent pom pluginManagement only when you need them, then you will have opportunity to test it as well. So steps are, start building a project which uses a given plugin not yet present in parent pom, add plugin to parent pom, release parent pom snapshot, make use of that snapshot in new project, if all OK release parent pom, and adjust reference to parent pom in new project. Later for another or same project if you need additional plugin or newer version of plugin already specified in parent pom, adjust parent pom, release new parent pom snapshot, check if it works for the given project, and if it does release parent pom, and adjust parent reference to newly released parent pom.
I have a multi module maven project and I would like to use versions in such a way that the developer has to touch only the root project pom to change the version of all modules.
For example
ProjA contains
Module1
Module2
Module3
All the modules contain their own Poms and have ProjA's pom as their parent. Once I run the build I get a jar created for each module. Now For building a newer version of ProjA, I just have to change the version of the ProjA's pom and all the poms of the modules should pick up this new version from the parent. This works if I harcode the parent version in all the module's pom. But this will also force me to update the poms of all modules for every version change in the parent pom which defeats it purpose.
Is there a way to avoid this and still achieve the stated behaviour?
Use the Maven Versions Plugin and its versions:update-child-modules goal:
versions:update-child-modules updates the parent section of the child modules of a project so the version matches the version of the current project. For example, if you have an aggregator pom that is also the parent for the projects that it aggregates and the children and parent versions get out of sync, this mojo can help fix the versions of the child modules. (Note you may need to invoke Maven with the -N option in order to run this goal if your project is broken so badly that it cannot build because of the version mis-match).
I changed the version from jFreeChart in the pom.xml of my maven project from 1.0.12 to 1.0.13.
Now I get the error
"The type org.jfree.ui.layer cannot be resolved to a type. It is indirectly referenced from required class files."
What does this mean? I just updated the jfreechart dependency.
The type is in the JCommons library. I think the problem is that the JFreeChart has not been properly distributed to maven in version 1.0.13. In the IBiblio directory listing, you can see that a .pom file is missing (as opposed to version 1.0.12, where it's present).
This means that maven has no ideas what the dependencies are. It still downloads the artifact through it's filename by convention, but it doesn't know anything about the context.
Now you can either complain to the vendor and demand a proper pom or create your own pom file (start with the old version and adjust it until things start working) and deploy it to your company's repository (or your local repository) using install:install-file or deploy:deploy-file.
My guess is that you'll at least have to include the following dependency
<dependency>
<groupId>jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.15</version>
</dependency>
(If you want to do it the easy way, just add the above dependency to your own project pom)