mavenmaven-pluginjava-17plexuseclipse-sisu

Bindings with Eclipse Sisu for Maven Plugin do not work for Java 17


Reproducible at: GitHub

I have a simple setup of a custom Maven plugin execution where I use PlexusContainer to perform a lookup for the defined containers.

import javax.inject.Inject;

...

@Mojo(
    name = "process-sources",
    defaultPhase = LifecyclePhase.PROCESS_SOURCES,
    instantiationStrategy = InstantiationStrategy.PER_LOOKUP,
    threadSafe = true
)
public class ProcessSourcesMojo extends AbstractMojo {

    @Inject
    private PlexusContainer container;

    @Parameter
    private String componentName;

    ...

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        if (container.hasComponent(MyComponent.class, componentName)) {
            try {
                final AbstractComponent myComponent = container.lookup(AbstractComponent.class, componentName);
                // USE THE COMPONENT
            } catch (ComponentLookupException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
}

I don't want to @Inject a particular one but rather resolve by type and name. The components are properly defined, for example:

@Named("myComponent")
public class MyComponent extends AbstractComponent {
}

Problem:

The whole problem lies in the used Java version as the newer Java versions cannot register the components properly.

Background:

I discovered that maven-plugin-plugin is responsible for generating descriptors picked up during the components scan. I have the following configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.9.0</version>
    <configuration>
        <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
    </configuration>
    <executions>
        <execution>
            <id>descriptor-help</id>
            <goals>
                <goal>helpmojo</goal>
            </goals>
        </execution>
    </executions>
</plugin>

I also use Eclipse Sisu plugin as suggested:

<plugin>
    <groupId>org.eclipse.sisu</groupId>
    <artifactId>sisu-maven-plugin</artifactId>
</plugin>

Dependencies

The minimum supported Maven version is 3.5.4.





I tried to update the versions up and down, but no luck with running on Java 17. What is the correct combination? Is Java 17 even supported?


Solution

  • When you want to compile Maven plugin for JDK 17+ you must use a Maven 3.9.6+ for executing.

    Related to issue: https://issues.apache.org/jira/browse/MNG-7913