I have a maven multi module project. If I need to branch, I use the maven-versions plugin to go through my project and update the parent version number rather easily. Is there a similar plugin to update my scm location in all of my poms?
Why don't you use the Maven Release Plugin and its release:branch mojo for that? From the Create a branch page:
Creating a branch executes the
following steps:
Check that there are no uncommitted changes in the sources
Change the version in the poms if you want to change it in the branch
(you will be prompted for the versions
to use)
Transform the SCM information in the POM to include the final destination
of the tag
Commit the modified POMs
Tag the code in the SCM as a new branch with a version name (this will
be prompted for)
Bump the version in the POMs if you want to change it to a new value
y-SNAPSHOT (these values will also be
prompted for)
Commit the modified POMs
Related
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).
Is there a way to specify the artifact version outside of the POM file?
I have 2 CI projects that build an artifact. One builds a "stable" development version from a 'develop' branch and the other builds an unstable version which is the result of merging all active feature branches into the develop branch. I want the stable version to build as xyz-1.0.jar and the integration build to go in as xyz-1.0-SNAPSHOT.jar. Is there a way for the CI job to run a maven task or specify via the command line if a release or snapshot jar should be built without manually modifying the POM? Currently I have the version specified as 1.0 in the pom. I considered using the release plugin but I don't want the automatic version number increase and tagging that it does.
Short answer: no. And here are some additional remarks:
It doesn't make much sense to use a "released" version (i.e. non SNAPSHOT) for a branch under CI since released versions are not downloaded again even if a newer version is available.
Released versions should be tagged (e.g. 1.0), maintenance is done is in a branch derived from the tag (e.g. 1.0.1-SNAPSHOT).
If you want to distinguish versions built from different branches, use different versions in the POMs.
I was able to accomplish this by using a property in my POM and then overriding it via the command line.
pom.xml:
...
<version>${artifactVersion}</version>
<properties>
<artifactVersion>1.0</artifactVersion> <!-- default version -->
</properties>
...
Then overriding with mvn -DartifactVersion=1.0-SNAPSHOT package
But Pascal's answer above is more in line with what I was really asking. My solution is more of a workaround I feel.
You should be able to achieve this using maven profiles
I am using Maven2. I have created a parent POM for my organization. I want the various groups will use it as a parent for their project but I want them to use the latest version.
for some reason, using it as a parent with version LATEST doesn't work,
any idea?
Thanks,
Ronen.
You don't need to define a new version for every small change you make in the POM.
The version means specific features of an artifact (in a POM are build settings), what I'd do is to declare one version and make all the projects use that version (to use a SNAPSHOT version is a great idea). If you make a small update do it in that version. If you make a bigger change you might want to declare a new version and have all the new POMs to use that version, this way you'll avoid to break old projects by using a new super POM.
Maven version plugin has a goal version:update-parent to set the parent version to the latest parent version.
Just execute
mvn versions:update-parent
in the project which you want to use latest parent version, it modifies the POM files for you.
I think you want to use SNAPSHOT, e.g.
<version>1.2-SNAPSHOT</version>
You need to run mvn with parameter -U in order to force the update of the local metadata files which hold the mappings for LATEST and RELEASE versions.
Could I disable SCM integration option in Maven? I want it to build a local checked-out project without SCM integration ?
is there some settings or some how??
thanx in advance
You should check if you're using Buildnumber Maven plugin.
By default and recommended configuration it is set to be invoked on "validate" phase of every build and will fail the build with this message.
If it is the case you have two options:
Disable the use of this plugin (by removing it from POM or moving it into special profile)
Add scm section as described above.
Hope this helps!
SCM integration is only used when you want to release a new version of software or generate changelog. When build a local checked-out project SCM integration is "ignored".
There is also scm-plugin but it isn't binded to none of the default lifecycles.
EDIT
According pom reference if you declare scm section it must be valid otherwise remove scm section.
Please paste your scm section or maybe scm plugin is used in pom.
If I have a parent pom and want to inherit this to several projects. I usually do this by adding in top of the project <parent> ... </parent>. What I don't like about this approach is that if something changes in my parent I have to edit all project which are inherited by that parent to modify the version number. Is there a better approach? I hope it is understandable what I'm trying to explain.
Thanks in advance.
What i don't like about this approach
is that if something changes in my
parent i have to edit all project
which are inherited by that parent to
modify the version number. Is there a
better approach?
Yes there is! Have a look at the Maven Versions Plugin, specifically:
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).
Edit: Of course, using Maven3 you can now have < version >-less < parent > elements in sub modules:
Developers working in multi-module or multi-pom projects won't have to specify the parent version in every sub-module in Maven 3. Instead, you can add version-less parent elements.
Ref
You can use the Maven Release Plugin when doing a release. It will update all the version numbers automatically and create a tag in your source control (if you have SCM configured in the POM).
My commands for performing a release are typically as follows, after which I export the tag from SCM and build it with "mvn clean package" or "mvn clean deploy".
svn update (or whatever SCM you use)
mvn clean
mvn release:prepare -DautoVersionSubmodules=true
mvn release:clean
So for example if you version is first "1.0-SNAPSHOT", then the release plugin will create a tag "projectname-1.0" with version "1.0", and finally increase the current version to "1.1-SNAPSHOT". The plugin will ask you for the versions and tag name, so you can override the defaults.
Automatic Parent versioning (i.e. omission of the tag) is a contentious issue in the Maven space. There is a defect logged against it. For now, it is being considered as a fix or improvement in the 2.1 version branch,
You should keep your versions as snapshots until it's time to release. This way you won't have to change it every time you change the pom. However once you've released a parent pom, you will want to make the change to all the children (assuming the parent is outside the "reactor" build...otherwise it would have been all bumped together by the release plugin). There is a relatively new plugin called the versions-maven-plugin that can assist with changing the versions.
I think the important thing to realize is that in a multi-module build, maven always uses the the version that is from your local repository. This applies in multi-module builds too! So when you reference the "parent" pom you're getting the published parent artifact from your local maven repository. So when you do mvn install you repeatedly publish each module to your local repo.
While developing, your own modules are probably versioned to something like X.X-SNAPSHOT. The reference to the parent-pom is X.X-SNAPSHOT. Don't change these before you're ready to release.
So a simple case would be:
Before initial release all modules are called 1.0-SNAPSHOT.
When makin the initial release "golden build", rename all 1.0-SNAPSHOT modules to 1.0.
When starting development on the 1.1 release, you change all version numbers to 1.1-SNAPSHOT.
And so on...
The custom is to work with snapshot versions until you're releasing, at which point you update the version numbers everywhere. In the day-to-day development you do not change the version numbers because snapshot-releases get treated differently than hard-version releases.
Edit:
After some thought I think some of your confusion in the "comments" section arises from this: The version number in your pom reflects the overall application version. Any given pom change does not necessarily change the application version number. If you need to track changes in the pom I would suggest you use a source control system. So in the 3 month period you work on version 1.0, it's reasonable to keep the version number at 1.0-SNAPSHOT. In the (for instance) 3 week period you work on 1.1, the version number is 1.1-SNAPSHOT.