Skip to content

Maven 4.0.0-rc-5 does not configure some MOJO parameters #11441

@desruisseaux

Description

@desruisseaux

Affected version

4.0.0-rc-5

Bug description

I tried to upgrade Maven JAR plugin from Maven 4.0.0-rc-4 to Maven 4.0.0-rc-5 with this commit. The JUnit tests pass, but 9 integration tests fail (22 passes). Many failures have the same cause:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:4.0.0-beta-2-SNAPSHOT:test-jar (default) on project maven-jar-plugin-test-mjar-199: Execution default of goal org.apache.maven.plugins:maven-jar-plugin:4.0.0-beta-2-SNAPSHOT:test-jar failed: basedir is not allowed to be null
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:346)
    (...strip...)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.apache.maven.plugins:maven-jar-plugin:4.0.0-beta-2-SNAPSHOT:test-jar failed: basedir is not allowed to be null
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:159)
    (...strip...)
Caused by: java.lang.NullPointerException: basedir is not allowed to be null
    at java.util.Objects.requireNonNull(Objects.java:246)
    at org.apache.maven.plugins.jar.AbstractJarMojo.getJarFile(AbstractJarMojo.java:218)
    at org.apache.maven.plugins.jar.AbstractJarMojo.createArchive(AbstractJarMojo.java:231)
    at org.apache.maven.plugins.jar.AbstractJarMojo.execute(AbstractJarMojo.java:301)
    at org.apache.maven.plugins.jar.TestJarMojo.execute(TestJarMojo.java:86)
    (...strip...)

By running the plugin in a debugger, we can see that the following field of AbstractJarMojo:

    /**
     * Directory containing the generated JAR.
     */
    @Parameter(defaultValue = "${project.build.directory}", required = true)
    private Path outputDirectory;

Is correctly set to a non-null value when running the jar goal, but is null when running the test-jar goal. The pom.xml contains the following:

    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>test-jar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>

The issue can be reproduced as below:

  • Checkout the master branch of https://github.com/apache/maven-jar-plugin
  • In the pom.xml, set <mavenVersion>4.0.0-rc-5</mavenVersion>.
  • Run mvn clean install with Maven 4.0.0-rc-5. Is should succeed.
  • Run -P run-its verify. There is test failures.
  • cd target/it/MJAR-199, which is the simplest test case.
  • mvn package --debug with a breakpoint on the getJarFile method. First execution is okay (the main JAR), the second execution is not (the test JAR).

Note: it seems to be a more generic issue than only the outputDirectory field. Doing the same experiment in MJAR-162, which contains a <skipIfEmpty>true</skipIfEmpty> configuration, the debugger tells me that the AbstractJarMojo.skipIfEmpty field stay false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions