Visitar URL original
Generated factory for a Maven 4 API mojo requires a no-arg constructor · Issue #1229 · apache/maven-plugin-tools · GitHub
Skip to content

Generated factory for a Maven 4 API mojo requires a no-arg constructor #1229

Open

Description

@slachiewicz

Affected version

4.0.0-beta-3; the code is unchanged on master

Bug description

For each Maven 4 API mojo, the descriptor goal generates a <Mojo>Factory subclass whose only constructor calls the mojo's no-arg constructor (DescriptorGeneratorMojo.java:530). A mojo that uses constructor injection and has no no-arg constructor builds cleanly, then fails when the goal runs:

Caused by: org.apache.maven.di.impl.DIException: Failed to call constructor public repro.ReproMojoFactory() to provide requested key @Named("repro:ctor-maven-plugin:1.0-SNAPSHOT:run") ReproMojoFactory
Caused by: java.lang.NoSuchMethodError: repro.ReproMojo: method 'void <init>()' not found

Reproducer, built with maven-plugin-plugin 4.0.0-beta-3 and run with Maven 4.0.0-rc-7:

@Mojo(name = "run")
public class ReproMojo implements org.apache.maven.api.plugin.Mojo {
    private final Log log;

    @Inject
    public ReproMojo(Log log) {
        this.log = log;
    }

    public void execute() {
        log.info("constructor-injected mojo ran");
    }
}

Expected: the factory mirrors the mojo's @Inject constructor and passes its parameters to super(...). Failing that, descriptor should reject a mojo without a no-arg constructor instead of producing a plugin that fails at run time.

The Maven 4 API ports in apache/maven#13302 had to switch mojos from constructor to field injection because of this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions