Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for property defined version update in the goal use-dep-version #474

Closed
amalakar opened this issue Jul 20, 2021 · 7 comments · Fixed by #878
Closed

Add support for property defined version update in the goal use-dep-version #474

amalakar opened this issue Jul 20, 2021 · 7 comments · Fixed by #878
Milestone

Comments

@amalakar
Copy link

I noticed that currently use-dep-version works only when the version is defined inline, as in the following works:

mvn versions:use-dep-version  -DdepVersion=2.3.1 '-Dincludes=javax.xml.bind:jaxb-api'
--- a/example/pom.xml
+++ b/example/pom.xml
@@ -80,7 +80,7 @@
         <dependency>
             <groupId>javax.xml.bind</groupId>
             <artifactId>jaxb-api</artifactId>
-            <version>2.3.0</version>
+            <version>2.3.1</version>
         </dependency>

But the following property defined version doesn't get updated:

    <properties>
      <jaxb.version>2.3.0</jaxb.version>
    </properties>

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>${jaxb.version}</version>
        </dependency>

This is a feature request to make use-dep-version work for property defined dependencies too.

Use case: we have many internal repositories which depends on few internal common libraries, sometimes we would want to update all of those repos to the latest version of the common libraries for bugs/security issues etc. But the downstream maven projects sometimes would have the version defined as a property or sometimes as inline version. If one command could handle both cases we could easily update all the repos to the target version.

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Jul 20, 2022
@amalakar
Copy link
Author

I am still interested in this feature/use case.

@github-actions github-actions bot removed the Stale label Jul 21, 2022
@jarmoniuk
Copy link
Contributor

So, the problem is that all properties are resolved (interpolated) when processed by the mojo. Whilst the is matched by the mojo, PomHelper is unable to replace the dependency version because it's unable to retrieve the sought string (containing the resolved property value) in the POM, so the POM is not getting updated.

Using a raw POM does help here; checking what the impact of changing that would be.

jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 18, 2022
@jarmoniuk
Copy link
Contributor

jarmoniuk commented Dec 21, 2022

Proposed new feature.

/**
 * <p>Will augment normal processing by, if a dependency value is set using a property, trying to update
 * the value of the property.</p>
 * <p>If the property value is specified directly, will process it normally (as with {@code processProperties} being
 * {@code false}. If the property being updated is redefined in the reactor tree, will only change the property
 * value which lies closest to the dependency being updated. If the same property is also used to set
 * the value of another dependency, will not update that property value, and log a warning instead. Finally,
 * if the property value is specified in a parent file which is outside
 * of the project, will log a warning message.</p>
 * <p>Default is {@code false}.</p>
 */
@Parameter(property = "processProperties", defaultValue = "false")
protected boolean processProperties;

The default value is false to retain backwards compatibility. I'd be wary of changing it.

What do you think, @slawekjaranowski @pzygielo?

jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 23, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 24, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
- changed to aggregator mode
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Dec 24, 2022
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
- changed to aggregator mode
@slawekjaranowski slawekjaranowski linked a pull request Dec 24, 2022 that will close this issue
jarmoniuk added a commit to jarmoniuk/versions-maven-plugin that referenced this issue Jan 2, 2023
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
- changed to aggregator mode
@slawekjaranowski slawekjaranowski added this to the next-release milestone Jan 3, 2023
slawekjaranowski pushed a commit that referenced this issue Jan 3, 2023
- adding a new parameter, processProperties, which will also update property values if dependencies are controlled by properties
- changed to aggregator mode
@amalakar
Copy link
Author

amalakar commented Jan 3, 2023

Thank you for supporting this use case!

@wollowizard
Copy link

Hi @amalakar and all, thanks for this feature. I do get a NullPointerException when using it:
mvn -o versions:use-dep-version -DprocessProperties=true -DdepVersion=3.0.0-SNAPSHOT -Dincludes={group}:*

Caused by: java.lang.NullPointerException
    at org.codehaus.plexus.util.StringUtils.deleteWhitespace (StringUtils.java:147)
    at org.codehaus.mojo.versions.api.PomHelper.setDependencyVersion (PomHelper.java:565)
    at org.codehaus.mojo.versions.AbstractVersionsDependencyUpdaterMojo.updateDependencyVersion (AbstractVersionsDependencyUpdaterMojo.java:536)
    at org.codehaus.mojo.versions.UseDepVersionMojo.useDepVersion (UseDepVersionMojo.java:366)
    at org.codehaus.mojo.versions.UseDepVersionMojo.processModel (UseDepVersionMojo.java:201)
    at org.codehaus.mojo.versions.UseDepVersionMojo.execute (UseDepVersionMojo.java:156)

can you confirm this is the right way to use it?

@jarmoniuk
Copy link
Contributor

jarmoniuk commented Mar 2, 2023

This will be fixed in the next release. Please use -DprocessDependencies=false as a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants