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

Fixes #426 restore default behavior on setting versions in all modules of the local aggregation root that was present before the fix for #82 #427

Merged
merged 1 commit into from Jan 11, 2022

Conversation

stefanseifert
Copy link
Contributor

introduce a new flag processFromLocalAggregationRoot that enables the new (and probably more correct) behavior by setting it it false
ensure old and new behavior are covered by integration tests

Fixes #426

…s of the local aggregation root that was present before the fix for #82

introduce a new flag processFromLocalAggregationRoot that enables the new (and probably more correct) behavior by setting it it false
ensure old and new behavior are covered by integration tests
@robinbanbury
Copy link

Any news on this? As we're starting to approach the anniversary of this PR :-)

@bmarwell
Copy link
Contributor

bmarwell commented Sep 1, 2021

Hey @robincsmith thanks for your PR! I will review it soon. Sorry for the delay! ;-)

@bmarwell
Copy link
Contributor

bmarwell commented Sep 1, 2021

Did a quick check with such a layout:

pom.xml
project-parent/pom.xml

Contents of /pom.xml:

   <parent>
     <groupId>invalid.company.project</groupId>
     <artifactId>project-parent</artifactId>
     <version>2.9.0-SNAPSHOT</version>
     <relativePath>project-parent/pom.xml</relativePath>
   </parent>

Executed:

mvn -X org.codehaus.mojo:versions-maven-plugin:2.9-SNAPSHOT:set -DnewVersion=2.9.0-SNAPSHOT -DgenerateBackupPoms=false
[...]
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.9-SNAPSHOT:set (default-cli) on project myproject: Project version is inherited from parent. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.9-SNAPSHOT:set (default-cli) on project myproject: Project version is inherited from parent.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Project version is inherited from parent.
    at org.codehaus.mojo.versions.SetMojo.execute (SetMojo.java:225)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

@robinbanbury
Copy link

Indeed. That matches the behaviour for version 2.7 and earlier:

$ mvn -X org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion=2.9.0-SNAPSHOT -DgenerateBackupPoms=false
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project test-project: Project version is inherited from parent. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.7:set (default-cli) on project test-project: Project version is inherited from parent.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: Project version is inherited from parent.
    at org.codehaus.mojo.versions.SetMojo.execute (SetMojo.java:215)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :test-project

The Maven invocation needs to include the link to the parent POM (as it did for versions <2.7) - in your case, -f project-parent/pom.xml:

mvn -X org.codehaus.mojo:versions-maven-plugin:2.9-SNAPSHOT:set -DnewVersion=2.9.0-SNAPSHOT -DgenerateBackupPoms=false -f project-parent/pom.xml

@bmarwell
Copy link
Contributor

bmarwell commented Sep 1, 2021

But that will not change any other pom files. E.g. the /pom.xml containing the version of the parent pom.

@robinbanbury
Copy link

Ah, in that case (from having a quick look at the RP), I think you may need to set -DprocessFromLocalAggregationRoot=false.

I'm not sure, as it's @stefanseifert 's PR. I'll try building their code.

@stefanseifert
Copy link
Contributor Author

the start of this story was bug #82, for which i provided the PR #400 which was merged and released.
however, after that lots of people complained that from their pov the previous behavior was not a bug but works as intended, summed up by @robincsmith in #426.

this PR restored the previous behavior to work exactly as it was for years in the previous versions of the plugin - but still allows to switch on the new behavior as described in #82. the new behavior only gets active when plugin property processFromLocalAggregationRoot is set to true (default is false).

ITs are included to cover both old and new behavior.

@robinbanbury
Copy link

@stefanseifert agreed - thanks for confirming.

@bmarwell I've just built the PR code, and the following should work for you, running in the project root directory:

mvn -X org.codehaus.mojo:versions-maven-plugin:2.9-SNAPSHOT:set -DnewVersion=1.2.3-SNAPSHOT -DgenerateBackupPoms=false -f project-parent/pom.xml

(i.e. no need to set any other flags, such as processFromLocalAggregationRoot)

@robinbanbury
Copy link

The only thing I can think is that you might have another snapshot version of the plugin installed? As the behaviour looks unchanged for you.

My plugin installation steps were just to checkout the PR code and run mvn clean install

@bmarwell
Copy link
Contributor

bmarwell commented Sep 1, 2021

Did the same, and as I use -X I can see the new property. Hmmm.

But if I use the file parameter and point to the parent not containing any modules, how would Maven know about the root? 🤷🏻‍♂️

I have another specialty in my project.
I manage module versions in my parent pom. Maybe I should not do this and just repeat the version everywhere.

@bmarwell
Copy link
Contributor

As soon as I started repeating the versions in all other modules again, it worked again.

gunnarmorling added a commit to moditect/moditect that referenced this pull request Oct 4, 2021
See mojohaus/versions#427, the parent POM in a sub-dir causes issues with 2.8.1.
@gunnarmorling
Copy link

Running into this in ModiTect as well; as a work-around, we've downgraded that invocation to 2.7 for the time being: https://github.com/moditect/moditect/blob/master/.github/workflows/trigger.yml#L87.

@bmarwell
Copy link
Contributor

bmarwell commented Oct 7, 2021

Well, we could just wait for maven 4 (where versions are not needed to be specified if the parent is local), or just use the workaround:
Always specify versions everywhere
Then execute mvn versions:set -DnewVersion=1.2.3 -pl my-project-parent.

@stefanseifert
Copy link
Contributor Author

if there are no objections i will merge this PR next week as lot of people seem to depend on the old behavior.
the new behavior is still available by setting processFromLocalAggregationRoot=false in the plugin config.

@stefanseifert stefanseifert changed the base branch from master to issue/426-local-root January 11, 2022 17:08
@stefanseifert stefanseifert merged commit ce83fdf into mojohaus:issue/426-local-root Jan 11, 2022
@stefanseifert
Copy link
Contributor Author

merged to master with 279d90a

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

Successfully merging this pull request may close these issues.

2.8.x: Unable to set project version when parent POM is in a project subdirectory
4 participants