I'm currently trying to extend org.codehaus.license.mojo:AggregatorAddThirdPartyMojo
.
I've created a class that extends AggregatorAddThirdPartyMojo
. It currently doesn't do anything more than its super class, I'm trying to make it work before customizing it to my need…
When I use the original plugin, I have no problem.
When I use my plugin, which should behave exactly as the original plugin at this point, it fails. In the super class code, it looks up another Mojo defined in the same package (AddThirdPartyMojo
) and doesn't find it in the Plexus container, failing the execution of the Mojo.
The exact error is :
[ERROR] Failed to execute goal org.example:report-maven-plugin:1.0-SNAPSHOT:my-goal (default-cli) on project BaseProject: could not execute goal MyMojo for reason : java.util.NoSuchElementException
[ERROR] role: org.apache.maven.plugin.Mojo
[ERROR] roleHint: org.codehaus.mojo:license-maven-plugin:2.0.0:add-third-party
I located the error and followed the stack trace, but it doesn't help. I don't know what is supposed to populate the Plexus container, why it's populated for the original plugin and not for mine.
Here is a minimal project that reproduces the problem :
│ pom.xml
│
│
├───leaf-module-a
│ pom.xml
│
├───leaf-module-b
│ pom.xml
│
└───report-maven-plugin
│ pom.xml
│
└───src
└───main
└───java
└───org
└───example
└───plugins
MyMojo.java
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>BaseProject</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>leaf-module-a</module>
<module>leaf-module-b</module>
<module>report-maven-plugin</module>
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<includeTransitiveDependencies>false</includeTransitiveDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.example</groupId>
<artifactId>report-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<inherited>false</inherited>
<configuration>
<includeTransitiveDependencies>false</includeTransitiveDependencies>
</configuration>
</plugin>
</plugins>
</build>
</project>
leaf-module-a/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>BaseProject</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>leaf-modyle-a</artifactId>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.0</version>
</dependency>
</dependencies>
</project>
leaf-module-b/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>BaseProject</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>leaf-module-b</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
</dependency>
</dependencies>
</project>
report-maven-plugin/pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>BaseProject</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>maven-plugin</packaging>
<artifactId>report-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.6.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>
report-maven-plugin/src/main/java/org/example/plugins/MyMojo.java
package org.example.plugins;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.mojo.license.AggregatorAddThirdPartyMojo;
@Mojo(name = "my-goal", aggregator = true, requiresDependencyResolution = ResolutionScope.TEST)
public class MyMojo extends AggregatorAddThirdPartyMojo {
}