Maven force update only for specific dependency (mvn -U for selected dependencies) - maven

The command mvn -U forcing all project dependencies to get updated from remote repository.
Is it possible to force such update for specific selection of dependencies, by explicit selection / by some logic?
The reasoning:
I don't want to force checking all the dependencies we have because how time consuming it is. All I need, is to verify a few of them or even specify only one dependency. So, such solution is highly desired.

There are two maven plugins that may help you here.
The first, dependency, will simply download the given version of a dependency:
mvn dependency:get -Dartifact=groupId:artifactId:version
The second, versions, offers some behaviors which you may also find helpful.
By running mvn versions:use-latest-releases -Dincludes=groupId:artifactId your project's pom will be updated with the latest release version of the dependency specified by the '-Dincludes' flag. You could then run the first command to download the version now referenced by your pom.
Both of these behaviors can be heavily customized and automated to do some quite awesome things. To get more help on a plugin goal, run: mvn plugin:help -Ddetail=true -Dgoal=goal
Example: mvn versions:help -Ddetail=true -Dgoal=use-latest-releases
For further information:
versions, dependency, and plugins

Related

SmartGWT 5 Maven Dependency,

Per a previous question on here, I was able to run:
mvn com.isomorphic:isc-maven-plugin:1.1.1:install -Dproduct=SMARTGWT -Dlicense=LGPL -DbuildNumber=5.0p -DbuildDate=2014-11-30
This did work. But I wonder ... do we need to do this again for the latest build? How do we even know where to find the latest build. I just want to use the latest, stable version, and not a nightly build.
Also, what is the correct dependency for SmartGWT 5.0p in my pom.xml file?
I have the old version which worked with 4.0, or do I need to use a new dependency? Is there anything else I might need to add to my pom.xml file?
Believe I hit Google for the last two days, and even on the SmartGWT Isomorphic site I still couldn't find a definitive answer.
Thanks for any help!
Due to Isomorphic licence scheme unfortunately if you need to update to a newer smartgwt build you cannot rely on maven "by design" features. You should run the install command again changing buildNumber or/and buildDate as desired.
Example
mvn com.isomorphic:isc-maven-plugin:1.1.1:install -Dproduct=SMARTGWT -Dlicense=LGPL -DbuildNumber=5.1p -DbuildDate=2016-01-07
The dependencies in your pom file should then use:
<version>5.1p-20160107</version>
where 5.1p corresponds to the buildNumber value and 20160107 to the buildDate.
Installed files are in ~/.m2/repository/com/isomorphic/smartgwt/lgpl you can check availability and versions there too.
By design, there is no answer: Maven dependency upgrades are manual.
When appropriate, you can look for new releases of your dependency (in this case SmartGWT), find out what the new version is called in the dependency's public Maven repository, update your project's POM, and update your local repository as necessary (mvn install like in the example, deleting old versions, etc.)

Updating the versions in a Maven multi-module project

I have Maven multi-module project and I would like to update the development versions to a given value using a script. The aggregator POM is only an aggregator and the children do not inherit from it. This is important because the artifacts all inherit from other POM files. Here is my structure
aggregator/
--projectA
--projectB
Also, projectB has a Maven dependency on projectA.
First I tried:
mvn -DnewVersion=0.28-SNAPSHOT -DupdateMatchingVersions=true versions:set
It only updated the aggregator project's version.
If I run the Maven release process, it correctly updates projectB's dependency on projectA to use the new development version after the release build. Because the release process handles this well, I thought that using the release plugin might solve my issue.
So I tried the following:
mvn -DdevelopmentVersion=0.28-SNAPSHOT -DautoVersionSubmodules=true --batch-mode release:update-versions
This updated all of my sub-projects correctly. However it did not update projectB's dependency version for projectA.
What is a simple way to update all the development versions in my project, including projectB's dependency on projectA?
You may have more luck with the release plugin but it may require some tweaking
versions:set is designed to update the version of the pom that it executes against... ie the root of the reactor.
If you follow it's conventions, then it will work... But you need to know its conventions.
When you have /project/parent/version and /project/version both specified but "accidentally" at the same value, the versions plugin assumes that the two versions are just accidentally the same, and so does not update the child project's version when the parent version is being updated. updateMatchingVersions tells the plugin to assume that it us not an accident and that the child should be in lock step.
If you only specify /project/parent/version and leave the project version unspecified, therefore relying on inheritance, the plugin will add the child project to the list of version changes (and hence loop through all the projects again to ensure it catches any additional required changes)
The versions plugin does not currently provide an option to force everything to the one version... Though that might be a good idea.
You can get what you want with three commands, eg
mvn versions:set -DnewVersion=...
cd projectA
mvn versions:set -DnewVersion=...
cd ../projectB
mvn versions:set -DnewVersion=...
This is because versions:set will attempt to "grow" the reactor if the parent directory contains an aggregator pom that references the invoked project...
In other words when you have a reactor with no common parent, versions assumes that the common version number is by accident, but it will pick up the intent from the wider reactor
# for each module into aggregator pom
for module in $(grep "\<module\>" pom.xml | sed 's/<\/module>//g' | sed 's/.*<module>//g' | sed 's/.*\///g')
do
# set the version of the module
# and update reference to this module into others modules
mvn versions:set -DgenerateBackupPoms=false -DartifactId=$module \
-DnewVersion=$newVersion -DupdateMatchingVersions=true
done
# set the version of the aggregator pom
mvn versions:set versions:commit -DnewVersion=$newVersion
i found your same problem ,then i clone versions plugin code , then I found if you set gropuId,artifcatId,oldVersion value tobe * will solve the problem;
like this :
mvn versions:set -DnewVersion=xxx -DgroupId=* -DartifactId=* -DoldVersion=*

Maven: change version properties in pom.xml

I have a Maven pom.xml, I build project and release project deploy with Jenkins.
But before and after build "release version" we need set my version in
For example:
I have in pom.xml
<properties>
<version-own>0.0.21-SNAPSHOT</version-own>
</properties>
before release I need set like this
<properties>
<version-own>0.0.25</version-own>
</properties>
after release I need set like this
<properties>
<version-own>0.0.27-SNAPSHOT</version-own>
</properties>
How can this be done?
If you don't have to use your own version property, consider the following that will operate on your <project><version>0.0.21-SNAPSHOT</version></project> element:
mvn versions:set versions:commit -DnewVersion="0.0.25"
That will modify your pom and adjust the version to your liking. You'll likely want to commit this change to your source code control repository, for this the scm plugin's scm:checkin goal works just fine (assuming you want this to be automated):
mvn scm:checkin -Dincludes=pom.xml -Dmessage="Setting version, preping for release."
Then you can perform your release (I recommend the maven-release-plugin), after which you can set your new version and commit it as above.
The versions plugin is your friend. Scripting the above would likely involve some parameterized build, or preferably the groovy plugin for jenkins which allows you to get the maven-specific build variables.
For starters, you can do it by hand. If your build follows maven conventions well, you could probably leverage one of a couple of maven plugins that exist for helping with the management of version numbers.
The maven-versions-plugin helps automate manual changes to version numbers. It has nice CLI commands to help tune up your poms before doing releases.
Then there's the maven-release-plugin that automates the whole process of cutting a release. It will change your snapshot to a release version, then roll it to the next snapshot after the release build. During all this process it commits discrete versions of the poms to source control.
Again, the secret to seeing success in the more automated bits of the maven community is whether your build is doing things the maven way or not. Hacked, highly tweaked, non-conventional builds usually have a lot of barriers to successful use of the release plugin.
There is one way to to that easily. With one command you can change whichever part you want:
For cut and paste:
mvn build-helper:parse-version versions:set -DbuildNumber=555 '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.incrementalVersion}-${buildNumber}'
For clarity:
mvn build-helper:parse-version versions:set -DbuildNumber=555
'-DnewVersion=
${parsedVersion.majorVersion}
.${parsedVersion.minorVersion}
.${parsedVersion.incrementalVersion}
-${buildNumber}'
This is a concise example how to update versions in one go with build values
Build-helper plugin supports regex replacements, and can even parse version numbers if need be.
http://www.mojohaus.org/build-helper-maven-plugin/
There is something like parsedVersion.nextIncrementalVersion
mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} versions:commit
Looking at this comment you are describing that you are using this version to provide a dependency. maven-release-plugin should help you manage the versions for you. So provide that plugin in your pom.xml.
And for the step of manually providing the release and development version, create a job in jenkins which will have 2 string parameters:
developmentVersion
releaseVersion
Add "Invoke top-level Maven targets" build step to execute the releasing (for example):
clean release:clean release:prepare release:perform -DdevelopmentVersion=${developmentVersion} -DreleaseVersion=${releaseVersion}
When building the job, it will prompt you to insert both the developmentVersion and releaseVersion.
Cheers,
Despot

Maven install:? - how to create a release candidate?

Is it possible to create a release candidate from my current maven project without changing the version number in the pom.xml?
I just want to build a new maven artifact form my project with a specific version number.
For example: my current pom.xml has the version '0.0.1'. I have called mvn install to create the artifact in my local repository. Now I would like to create a second artifact with the version '0.0.1-RC1'
Is this possible from the mvn command line without changing the version number in my pom.xml?
I would advice against your suggestion of not changing the version number. One of the Maven's benefits is to keep your releases in sequence, i.e. after you have made your '0.0.1-RC1' candidate you will continue to work on the '0.0.1-RC2-SNAPSHOT' version (which may result in a '0.0.1-RELEASE').
That said, you don't have to change the version number manually. The Maven Release Plugin offers great help with this with commands such as mvn release:prepare and mvn release:perform. Also read the Maven build versions in the Maven reference manual. You may also find the discussion about Maven version scheme interesting.
As I see it you have two options:
Embrace the release plug-in. It's been designed to address this problem.
Use the versions plug-in and issue your own source code control commands.

Maven3 - How do I found dependency resolution? ( mvn depedency:tree does not work for mvn3 )

With maven-3, it uses aether to resolve dependency.
Unfortunately, "mvn dependency:tree" use legacy (maven-2) resolution engine.
How do I find out the true dependency resolution for maven-3. I'm running into an issue where "exec:exec" creates different classpath then "dependency:tree".
In maven 3 - compatibility notes, it says I need to use "-X" and look at the log but there is no pointer what to look for.
Also, "assembly:assembly" brings in different 'jar' than when I print out classpath from "exec:exec".
dependency:tree is the correct way to get the project dependencies. Since version 2.5 of the plugin it now resolves the tree using aether.
exec:exec runs the maven exec plugin. The classpath it generates is based on the plugin dependencies, if specified. It is relevant only for the purpose of the plugin execution and not to be taken in the context of project.
The similar explanation holds good in case of assembly:assembly. The jars that it brings in entirely depends on the plugin and assembly-descriptor configuration.
Since version 2.5 of the Maven Dependency Plugin, dependency:tree works with Maven 3 (see the bug report, and the release notes)

Resources