mojohaus / versions

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

use-latest-releases and use-latest-snapshot does not resolve properties from parent anymore #969

Closed Nomad95 closed 4 months ago

Nomad95 commented 1 year ago

Hi,

in version 2.15.0 plugin does not resolve properties from parent anymore

Example dependency in dependencyManagement root POM:

<dependency>
       <groupId>${project.groupId}</groupId>
       <artifactId>some-artifact</artifactId>
       <version>3.46.0</version>
</dependency>

Command i am using:

mvn org.codehaus.mojo:versions-maven-plugin:2.15.0:use-latest-releases \
      -DallowSnapshots=false \
      -DallowDowngrade=true \
      -DallowMajorUpdates=true \
      -DallowMinorUpdates=true \
      -DallowIncrementalUpdates=true \
      -Dexcludes="excluded.1:*:*:*:*,excluded.2:*:*" \
      -Dincludes="my.project.id:*:*:*:*" \
      -DgenerateBackupPoms=false \
      -U

Plugin is not updating dependencies that have ${project.groupId} property in groupId tag, even though it resolves to "my.project.id". It doesn't work for Either snapshot nor release versions. I was using 2.13.0 earlier and it was working properly.

jarmoniuk commented 1 year ago

Hi. Strangely, I'm unable to reproduce this with 2.13.0, 2.14.2, latest snapshot, or even with 2.15.0. I'm using the following test case:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>localhost</groupId>
  <artifactId>it-use-next-releases-props</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>dummy-api</artifactId>
      <version>1.1.1</version>
    </dependency>
  </dependencies>

</project>

invoker.properties:

invoker.goals = ${project.groupId}:${project.artifactId}:2.15.0:use-latest-releases

verify.groovy:

import groovy.xml.XmlSlurper
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
assert project.dependencies.dependency.version == '3.0'

Properties are being resolved using the use-latest-releases goal and we can see the dependency bumped to 3.0.

(Removing the edited section since I wasn't using invoker.mavenOpts properly. Still cannot reproduce even with -U passed to maven).

jarmoniuk commented 1 year ago

Also didn't manage to reproduce it when the project was using a property from parent:

parent-pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>default-group</groupId>
    <artifactId>parent-artifact</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>

    <properties>
        <group>localhost</group>
    </properties>

</project>

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>default-group</groupId>
    <artifactId>parent-artifact</artifactId>
    <version>1.0.0</version>
    <relativePath>parent-pom.xml</relativePath>
  </parent>

  <groupId>localhost</groupId>
  <artifactId>it-use-next-releases-props</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>

  <dependencies>
    <dependency>
      <groupId>${group}</groupId>
      <artifactId>dummy-api</artifactId>
      <version>1.1.1</version>
    </dependency>
  </dependencies>

</project>

All the same, the dependency is being bumped to the latest release...