version updates while updating maven inherited properties - maven

I have multiple maven multi-module projects and one parent project. Parent project pom.xml file is the parent of all other projects' root pom.xml.
-> ParentProject
pom.xml
->Project1
-> module1
src
pom.xml
-> module2
src
pom.xml
->pom.xml
->Project2
-> module1
src
pom.xml
-> module2
src
pom.xml
->pom.xml
In the parent pom.xml file, I have a couple of properties which are inherited and used by others. I need to update those properties quite frequently, and if I increase the version of parent pom after updating those properties, I need to update other poms and increase their versions as well. Is there any way to prevent it, or is there a better way to do it? Thanks!

You can use the versions plugin to help with the tedium: Update the ParentProject version (and install locally) and then run mvn versions:update-parent to update the parent version in Project1 and Project2.
There are other useful targets for updating properties and dependencies.

Related

Sharing plugin versions between reactor and parent pom in a multi-module maven project

I have a multi-module maven project with a reactor pom that I use to build the whole project, and a parent pom which all child modules inherit from.
There is a plugin I need to have in both the reactor and the parent poms, meaning I have a separate use for the plugin in the child modules and in the reactor pom used to aggregate the build. I'd like to manage the version of this plugin in one file, instead of manually changing it in both files every time.
Example:
Project structure:
--pom.xml //reactor pom - aggregates the build (contains the plugin)
----parent/pom.xml //parent pom - all child modules inherit this pom (contains the plugin)
----a/pom.xml //module a - inherits parent/pom.xml
----b/pom.xml //module b - inherits parent/pom.xml
----c/pom.xml //module c - inherits parent/pom.xml
Note: the parent pom is inherited by child modules only. Not by the reactor.
any help is greatly appreciated, thanks in advance

maven - need to create ear bundle

I have a maven project which currently creates a war package on build. Now I need to bundle it as an ear project. Any pointers on how to do this. I added the m2e plugin and modified the pom.xml file, but, i am not able to get the directory structure as expected. I need the dir structure as below
project-name
- project-name.ear
- pom.xml
- project-name.war
- projec-name.jar
- META-INF/application.xml
Thanks.
It is strongly recommend that you organize your project structure in proper Maven style:
project-name/
- pom.xml (POM of project-name, multi-module POM)
+ project-name-jar
- pom.xml (main app JAR)
+ project-name-web
- pom.xml (WAR project to construct WAR by project-name-jar etc)
+ project-name-ear
- pom.xml (EAR project to construct EAR by project-name-war etc)
Normally I will have another child project call project-name-parent which use as parent POM for the whole project.
In Maven, you don't and you shouldn't have META-INF/application.xml as part of your source. It is generated dynamically base on configuration of maven-ear-plugin.

Multi Module Maven Parent POM

There are multiple modules in my application . All of them are maven projects .
So I am working on creating a parent pom for all these projects and was able to create one and ran maven build on this parent pom and works fine build
But when I opened the project in eclipse , the parent pom was not included in the projects displayed so it was picking it up for the build process to take place . My project structure is as follows
ProjectA
|
--------subProjects
ProjectB
|
--------subprojects
ProjectC
|
--------subProjects
ProjectD
|
-------subprojects
Pom.xml
So what do I need to make an eclipse recognise this parent pom ? I created another maven module and made it parent pom . But is there any way i could avoid creating another project and achieve the above scenario ?
One thing you can do is to import the global structure as a maven project on its own and then import the subprojects one by one as maven project in eclipse.
you can use mvn eclipse:eclipse in the command line for all the project one by one, and then you can select by importing(Maven Project Type) all the maven projects if you select the directory on the top of your maven projects.
In this case you make all settings in the pom and no additional configs in eclipse.

Independently building Maven submodules

After being introduced to Maven in my most recent project, I've been experimenting with it for the past couple of weeks.
I currently have a multi-module project in my development environment. Project "A" and Project "B" are child modules of Project "root", with B having a dependency on A.
I am aware that I can build B independently by using mvn reactor:make... as outlined here. However, I'm curious as to why am I not allowed to build B from inside B's root folder.
To illustrate this, I first built A independently by running a clean install from within A's root directory. However, when I tried doing the same action from B's root directory, Maven reported an error as below -
Could not find artifact org.divesh.mavenrnd:root:pom:1.0 in central
It looks like Maven is not able to resolve the parent's POM file. Any thoughts on why this is happening? From my initial understanding of Maven multi-module projects, the main reason to split a project into sub modules is to share dependencies. This should not, however, prevent me from building a particular module independently from within its folder.
Thanks.
EDIT
Ran an mvn -N clean install to install only the root project's POM in the rep. After this, I was able to successfully build B after building and installing A. There is still one thing I'm not quite clear about -
Assuming I've installed the root project's POM in the repository, if I try to build A, does it refer to the parent root POM directly above it or the POM that is installed in the repository?
That's right. The error you mentioned tells you that maven cannot find parent's pom.
You have 2 options here:
First call mvn -N install in your root project directory to install parent pom to your local repository. Then you can go to B's directory and build the submodule.
Specify <relativePath> in your submodule pom. By default maven will look for parent pom only one level up the file system. If you have other directory structure in your project, you have to specify this option in order for maven to locate your parent pom.
Here's a sample:
<parent>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<relativePath>../../pom.xml</relativePath>
</parent>
You should use mvn -pl ProjectToBuild lifecycle like from the root of your tree:
mvn -pl module-b package
You shouldn't use mvn reactor:make anymore. Except you are using maven 2.0
If you wan't to be sure that everything is depending on module-b is build as well you should use:
mvn -amd -pl module -b package
The best is having a folder layout which represents the appropriate structure of your project and not using relativePath is necessary.

Maven project structure

In svn repository I have a folder 'product' under which are all my Eclipse plugins and features, parallel to these there is parent POM. This setup works well when I build in Jenkins, I just check out 'product' and install pom.xml. However, I can't figure out how this setup works in Eclipse workspace? I can't check out pom.xml by itself into workspace, and if I do I need to check it out as single file under a project which brakes path to parent POM. How should I check out and build in such setup?
Also, do I need to define relativePath of parent POM in my plugins? I found that if I omit it, then I get error about path being missing.
Just to summarize, my svn repository structure is this:
repo/
trunk/
product <- maven project (folder with .project set as maven nature)
pluginA
pluginB
featureA
pom.xml
.project
I think you have two options:
Deploy your parent POM to a locally available repository, perhaps your company Nexus server, for example? This will then be available to all products and for all your colleagues.
Restructure your project to look more Maven-like, e.g.
|-- plugin1
|-- pom.xml
|-- ....
|-- plugin2...
|-- feature1...
|-- ...
pom.xml <-- parent POM
This second option may be better in the long term, otherwise your Jenkins server relies on you remembering to locally install the updated parent POM, rather than just plucking it from svn.
If you use m2eclipse (e.g. available from the Juno site), you can import any Maven project structure into Eclipse. In your case, the product folder would be imported as an Eclipse project, as well as the individual features and bundles.
<relativePath> defaults to .., so you need to specify it if the parent POM is not in the parent folder. You can set it to undefined (e.g. through an empty <relativePath/> tag) if the parent POM is not available locally. In this case, Maven will always resolve the parent POM from the local Maven repository or the configured remote (Maven) repositories.

Resources