Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] Generated classes are not picked up by Sisu, even though the javax.inject.Named file contains them #163

Open
HomeOfTheWizard opened this issue Jul 14, 2023 · 1 comment

Comments

@HomeOfTheWizard
Copy link
Contributor

HomeOfTheWizard commented Jul 14, 2023

Hi,

My issue may not be an issue on the plugin, but in my usage of it.
I am developping a plugin that uses JSR330 annotations.

During the "Compile" phase of maven lifecycle, I am generating at runtime some javax.inject.Provider classes that are tagged with @Named JSR330 annotations and storing them in the classpath.
image

Here is the decompiled class

package com.homeofthewizard;

import com.homeofthewizard.hellolib.MyFriend;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;

@Named
public class MyFriendProvider implements Provider<MyFriend> {

    public MyFriend get() {
        return new MyFriend();
    }
}

During Package phase, the sisu-maven plugin takes them into account when indexing. I checked the file generated and all seems ok.

com.homeofthewizard.MyFriendProvider
org.apache.maven.DefaultArtifactFilterManager
org.apache.maven.ReactorReader
org.apache.maven.classrealm.DefaultClassRealmManager
org.apache.maven.execution.DefaultMavenExecutionRequestPopulator
org.apache.maven.execution.scope.internal.MojoExecutionScopeCoreModule
org.apache.maven.extension.internal.CoreExportsProvider
....

But when I execute my plugin, the classes are not found, and the providers are not injected by sisu.
Here is my mojo:

package com.homeofthewizard;

import com.homeofthewizard.hellolib.MyFriend;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Mojo;
import org.codehaus.plexus.logging.Logger;

import javax.inject.Inject;

@Mojo( name = "sayhi")
public class MyMojo extends AbstractMojo
{
    private final Logger logger;
    private final MyFriend helloer;

    @Inject
    public MyMojo(Logger logger, MyFriend helloer) {
        this.logger = logger;
        this.helloer = helloer;
    }

    public void execute()
    {
        logger.info("executing mojo");
        helloer.hello();
    }
}

Here is the error:

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.486 s
[INFO] Finished at: 2023-07-14T17:44:47+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT:sayhi (default-cli) on project spring-bridge-demo-maven-plugin: Execution default-cli of goal com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT:sayhi failed: Unable to load the mojo 'sayhi' (or one of its required components) from the plugin 'com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT': com.google.inject.ProvisionException: Unable to provision, see the following errors:
[ERROR] 
[ERROR] 1) null returned by binding at org.eclipse.sisu.wire.LocatorWiring
[ERROR]  but the 2th parameter of com.homeofthewizard.MyMojo.<init>(Unknown Source) is not @Nullable
[ERROR]   at org.eclipse.sisu.wire.LocatorWiring
[ERROR]   while locating com.homeofthewizard.hellolib.MyFriend
[ERROR]     for the 2th parameter of com.homeofthewizard.MyMojo.<init>(Unknown Source)
[ERROR]   while locating com.homeofthewizard.MyMojo
[ERROR]   at ClassRealm[plugin>com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@512ddf17] (via modules: org.eclipse.sisu.wire.WireModule -> org.eclipse.sisu.plexus.PlexusBindingModule)
[ERROR]   while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value="com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT:sayhi")
[ERROR] 
[ERROR] 1 error
[ERROR]       role: org.apache.maven.plugin.Mojo
[ERROR]   roleHint: com.homeofthewizard:spring-bridge-demo-maven-plugin:1.0-SNAPSHOT:sayhi
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginContainerException

Process finished with exit code 1

I am using maven 3.9.1
Java 11 as source and bytecode.

Am I missing something here ? Can you please help me pinpoint the issue ? 🙏

@mcculls
Copy link
Contributor

mcculls commented Jul 14, 2023

Hi @HomeOfTheWizard - have you tried turning on debug with -Dsisu.debug to get more information?

It's possible that there's a missing class/dependency somewhere which is causing that class not to load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants