mojohaus / versions

Versions Maven Plugin
https://www.mojohaus.org/versions/versions-maven-plugin/
Apache License 2.0
337 stars 267 forks source link

Using use-dep-version to override a version defined in a parent POM #982

Closed vmckinney-cainc closed 1 month ago

vmckinney-cainc commented 1 year ago

Hi all,

I am wondering if it is possible to use use-dep-version in a child project to override a dependency version defined in a parent.

For example, in a parent POM:

<properties>
  <example.artifact.version>1.2.3</example.artifact.version>
</properties>
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>example.group</groupId>
      <artifactId>example-artifact</artifactId>
      <version>${example.artifact.version}</version>
    </dependency>
  </dependencies>
</dependencyManagement>

Then, in a child that consumes the parent:

mvn versions:use-dep-version -e -Dincludes=example.group:example-artifact -DdepVersion=1.2.4 -DforceVersion=true -DprocessProperties=true -DprocessDependencyManagement=true -DprocessParent=true

I get this error:

[WARNING] Not updating ... in dependencies: version defined in dependencyManagement

Looking at the code: https://github.com/mojohaus/versions/blob/0b860eb781f139eb126a4952d51e87e9bc31f63b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java#L357-L360

It seems this happens when the version is null, which I assume is because it's not grabbing the version from the parent. Does the functionality to override versions defined in the parent exist in versions-maven-plugin? If so, is there an obvious issue here? If the functionality exists and you need a minimal reproducible example I can create one -- the actual codebase this fails in is private.

Thank you!

dasteg commented 1 year ago

struggling with this as well at the moment. trying to do some "overrides" during a specific phase of development. since dependencies are inherited the use-dep-version goal doesn't do anything.

what works (but quite complicated) is to add a dummy version element in the pom and then replace it with the correct version.

github-actions[bot] commented 2 months ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 30 days.