I would like to set the version of a dependency in a POM from command line. Much like versions:set
(for the version of the project), but for a specific dependency.
I don't want to craft any XML scanning tool because there are various ways to specify a version and it is hard to handle them all.
If you know your dependency versions are specified in the dependency
or dependencyManagement
blog and the version is not a property you can use use-dep-version:
mvn versions:use-dep-version -Dincludes=io.netty:netty-all -DdepVersion=1.0 -DforceVersion=true
However if the version is specified as a property, the use-dep-version
will not work.
Then you can only use versions:*-property
commands but for this you need to know the name of the property (which could be achieved by having a naming convention for these properties)
mvn versions:set-property -DnewVersion=1.0 -Dproperty=netty-all.version
if you need more safety that the version you will use is valid or to avoid downgrades have a look at update-property.
If you project is mixed with versions and property versions you could just run both commands and one will change it.
UPDATE 2024: Maven goal use-dep-version
now has attribute processProperties, which if set to true
will cause also properties to be changed. There is no need for using versions:*-property
anymore.