mojohaus / exec-maven-plugin

Exec Maven Plugin
https://www.mojohaus.org/exec-maven-plugin/
Apache License 2.0
166 stars 97 forks source link

NullPointerException under Maven 4.0.0-m10 #401

Closed nielsbasjes closed 7 months ago

nielsbasjes commented 9 months ago

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 commented 9 months ago

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 commented 8 months ago

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...)