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.
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 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 maven multi-modules project. At the parent level, i have some java files. And in the parent pom.xml, at the package phase i do some stuff.
Usually, when i run mvn package at parent level, the package phase of parent pom will be run and all the modules will be packaged as well.
I am looking for a way that allow me to do these (when i run mvn package):
allow me to run only paren pom.xml (the script at the package phase), not the modules. This is the 1st priority.
allow me to run paren pom.xml and some particular modules (like module 1, module 2 BUT not module 3 , module 4).
Can i use profile for those issue?
Thanks.
While I agree with the fact that you may not have optimal project structure, the answer is that Maven 2.2.1 has an option "--non-recursive" which satisfies your first requirement:
-N,--non-recursive Do not recurse into sub-projects
So something like this:
mvn --non-recursive clean compile
Why do you want to have java code on the top level? In my opinion this is not a very good idea. Have your code in the subprojects and let the top-level project be responsible for holding the general information and configuration of the entire project.
If you have some base-library code in the top-level project now, you can put it in a sub-project and set up dependencies between the projects.
Take a look at Maven parent pom vs modules pom
The nature of your question indicates that your project structure may not be optimal.
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 have a parent pom whose packaging type is jar.
Then I have a child pom whose packaging is war. I want to include the packaged parent jar in WEB-INF/lib of the packaged child.
How do I achieve this?
I'm not sure to understand (a parent pom with a jar packaging, is this working?) but the "normal way" would be to add a dependency on the JAR artifact in your WAR project. But I think that you know that and that there is a problem (which is the part that is unclear).
Maybe you could use the dependency plugin instead. Use dependency:copy to get the dependency and copy it to ${project.build.directory}/${finalName}/WEB-INF/lib during prepare-package.