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

NPE upon versionless dependencies in dependencyManagement #442

Closed
ryenus opened this issue Jan 2, 2021 · 8 comments · Fixed by #452
Closed

NPE upon versionless dependencies in dependencyManagement #442

ryenus opened this issue Jan 2, 2021 · 8 comments · Fixed by #452

Comments

@ryenus
Copy link

ryenus commented Jan 2, 2021

When running mvn versions:resolve-ranges with versions plugin 2.8.1, it fails with NullPointerException, which seems to be related to dependencies without versions, such as junit:junit:jar

In one of our parent pom, we use org.eclipse.m2e:lifecycle-mapping in a way similar to what described here: https://stackoverflow.com/a/7423909/537554
<dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
      </dependency>
   </dependencies>
</dependencyManagement>
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.8.1:resolve-ranges (default-cli) on project lbn-das-service: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.8.1:resolve-ranges failed.: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.8.1:resolve-ranges (default-cli) on project lbn-das-service: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.8.1:resolve-ranges failed.
    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 sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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.PluginExecutionException: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.8.1:resolve-ranges failed.
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    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 sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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: java.lang.NullPointerException
    at org.codehaus.mojo.versions.AbstractVersionsDependencyUpdaterMojo.isHandledByProperty (AbstractVersionsDependencyUpdaterMojo.java:194)
    at org.codehaus.mojo.versions.ResolveRangesMojo.resolveRanges (ResolveRangesMojo.java:217)
    at org.codehaus.mojo.versions.ResolveRangesMojo.update (ResolveRangesMojo.java:126)
    at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.process (AbstractVersionsUpdaterMojo.java:315)
    at org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo.execute (AbstractVersionsUpdaterMojo.java:250)
    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 sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    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)
@ryenus ryenus changed the title NPE with org.eclipse.m2e:lifecycle-mapping NPE upon versionless dependencies in dependencyManagement Jan 3, 2021
ryenus added a commit to ryenus/versions-maven-plugin that referenced this issue Jan 3, 2021
@mfriedenhagen
Copy link
Member

What is your expectation here? Specifying dependencies without a version is a bug. Maven is all about fixating versions of dependencies and plugins to stabilize the build. I agree that the plugin could behave a little better :-)

@ryenus
Copy link
Author

ryenus commented Feb 26, 2021

The idea is that instead of blow up, it should try to help to indicate what's the problem or where it comes. Such as to report the dependencies for which the versions are missing, or even better with line numbers, etc.

@mfriedenhagen
Copy link
Member

I would agree to throw a MojoFailureException with the groupId and artifactId of the conflicting dependency, just skipping over it seems wrong to me:

<project>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>foo</artifactId>
    <groupId>bar</groupId>
    <version>1.0</version>
    <dependencyManagement>
       <dependencies>
          <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
          </dependency>
       </dependencies>
    </dependencyManagement>
    <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
      </dependency>
    </dependencies>
</project>

When running mvn validate this already fails. So: why don't you specify a version? Concerning the m2e problem: I was involved in another stackoverflow thread and the solution with the profile seems appropriate.

@ryenus
Copy link
Author

ryenus commented Mar 2, 2021

Thank you @mfriedenhagen. Even though mvn validate would fail on this, but other more frequently used ones such as mvn test or mvn package possibly even mvn deploy. Nevertheless the code is inherited from parent/grand pom which was authored by others, so somehow the issue crept in without being noticed in the first place.

@mfriedenhagen
Copy link
Member

test, package and deploy will fail as well, as they are phases which come after validate and so will never be reached.

mvn validate does throw org.apache.maven.project.ProjectBuildingException but this is not appropriate for a plugin, so I would go for throwing a MojoFailureException in this case.

@ryenus
Copy link
Author

ryenus commented Mar 7, 2021

BTW, in the original case, the unversioned junit only appears in the dependencyManagement section, and not in dependencies.

@mfriedenhagen
Copy link
Member

I know, it seems mvn validate does not inspect the dependencyManagement section.

mfriedenhagen added a commit that referenced this issue Mar 19, 2021
 * `mvn` validate does choke on dependencies without versions.
 * However in managed dependencies a missing version is ignored.
 * resolve-ranges does throw a NPE, which is not helpful.
 * So fail with available coordinates to make fixing easier.
 * When the artifactId is missing in a managed dependency Maven core
will aready fail.

Resolve #442
mfriedenhagen added a commit that referenced this issue Mar 19, 2021
 * `mvn validate` does choke on dependencies without versions.
 * However in managed dependencies a missing version is ignored.
 * resolve-ranges does throw a NPE, which is not helpful.
 * So fail with available coordinates to make fixing easier.
 * When the artifactId is missing in a managed dependency Maven core
will aready fail.

Resolve #442
obfischer pushed a commit to obfischer/fork-of-versions-maven-plugin that referenced this issue Jun 25, 2021
 * `mvn validate` does choke on dependencies without versions.
 * However in managed dependencies a missing version is ignored.
 * resolve-ranges does throw a NPE, which is not helpful.
 * So fail with available coordinates to make fixing easier.
 * When the artifactId is missing in a managed dependency Maven core
will aready fail.

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

Successfully merging a pull request may close this issue.

2 participants