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

NullPointerException under Maven 4.0.0-m10 #401

Closed
nielsbasjes opened this issue Dec 21, 2023 · 2 comments · Fixed by #414
Closed

NullPointerException under Maven 4.0.0-m10 #401

nielsbasjes opened this issue Dec 21, 2023 · 2 comments · Fixed by #414
Assignees
Labels

Comments

@nielsbasjes
Copy link

Put this pom.xml in an empty directory:

<?xml version="1.0"?>
<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>nl.basjes.bugreport</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>3.1.1</version>
        <executions>
          <execution>
            <id>Just say hello</id>
            <phase>validate</phase>
            <goals>
              <goal>exec</goal>
            </goals>
            <configuration>
              <executable>bash</executable>
              <arguments>
                <argument>-c</argument>
                <argument>echo Hello world</argument>
              </arguments>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

Doing mvn validate using maven 3.9.6 I get this

[INFO] --- exec:3.1.1:exec (Just say hello) @ problem ---
Hello world

Doing mvn validate using maven 4.0.0-m10 I get this (wrapped for readability)

[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.1:exec (Just say hello) on project demo: 
    Execution Just say hello of goal org.codehaus.mojo:exec-maven-plugin:3.1.1:exec failed: 
    Cannot invoke "org.codehaus.plexus.PlexusContainer.lookup(String)" because the return value 
      of "org.apache.maven.execution.MavenSession.getContainer()" is null -> [Help 1]

The stacktrace where it fails:

Caused by: java.lang.NullPointerException: Cannot invoke "org.codehaus.plexus.PlexusContainer.lookup(String)" because the return value of "org.apache.maven.execution.MavenSession.getContainer()" is null
    at org.codehaus.mojo.exec.ExecMojo.getToolchain(ExecMojo.java:945)
    at org.codehaus.mojo.exec.ExecMojo.getExecutablePath(ExecMojo.java:751)
    at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:395)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:144)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:318)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:214)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:175)
@cstamas
Copy link

cstamas commented Dec 21, 2023

The method org.apache.maven.execution.MavenSession.getContainer() has been deprecated 9 years ago, it would be really a time to move off from that method.

@rmannibucau
Copy link
Contributor

If it helps, here is a workaround:

${java.home}/bin/java

Idea is to pass an existing path to the executable value, this way toolchain is not used (it is wrongly used anyway since you don't want to use java from toolchain but from the env...)

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

Successfully merging a pull request may close this issue.

4 participants