square / dagger

A fast dependency injector for Android and Java.
https://square.github.io/dagger/
Apache License 2.0
7.31k stars 3.06k forks source link

No methods listed for "You have these unused @Provider methods" #429

Open fbiville opened 10 years ago

fbiville commented 10 years ago

Hi, I have this module:

package com.vidal.rest.sdk;

import com.vidal.rest.sdk.converters.AtomConverter;
import com.vidal.rest.sdk.converters.AtomDeserializerFactory;
import dagger.Module;
import dagger.ObjectGraph;
import dagger.Provides;
import retrofit.RestAdapter;
import retrofit.converter.Converter;

@Module
public class VidalAPI {

    private final String uri;

    private VidalAPI(String uri) {
        this.uri = uri;
    }

    public static Resources at(String uri) {
        ObjectGraph graph = ObjectGraph.create(new VidalAPI(uri));
        return graph.get(ResourceFactory.class);
    }

    @Provides
    ResourceFactory resourceFactory(RestAdapter restAdapter) {
        return new ResourceFactory(restAdapter);
    }

    @Provides
    RestAdapter restAdapter(Converter converter) {
        return new RestAdapter.Builder()
                .setConverter(converter)
                .setEndpoint(uri)
                .build();
    }

    @Provides
    Converter converter(AtomDeserializerFactory deserializers) {
        return new AtomConverter(deserializers);
    }

    @Provides
    AtomDeserializerFactory deserializers() {
        return new AtomDeserializerFactory();
    }

}

Whenever I try building the project, I get this:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/fbiville/Projects/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[11,7] error: Graph validation failed: You have these unused @Provider methods:
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

Without any faulty methods listed >:(. I guess that's a bug, or?

cgruber commented 10 years ago

I believe that is must maven hiding your error message detail. Please use "mvn -e" (or mvn -X) to get more detail on the error messages.

On 7 August 2014 04:41, @fbiville notifications@github.com wrote:

Hi, I have this module:

@Module public class VidalAPI {

private final String uri;

private VidalAPI(String uri) {
    this.uri = uri;
}

public static Resources at(String uri) {
    ObjectGraph graph = ObjectGraph.create(new VidalAPI(uri));
    return new ResourceFactory(graph.get(RestAdapter.class));
}

@Provides
RestAdapter restAdapter(AtomConverter converter) {
    return new RestAdapter.Builder()
            .setConverter(converter)
            .setEndpoint(uri)
            .build();
}

@Provides
AtomConverter converter(AtomDeserializerFactory deserializers) {
    return new AtomConverter(deserializers);
}

@Provides
AtomDeserializerFactory deserializers() {
    return new AtomDeserializerFactory();
}

Whenever I try building the project, I get this:

[INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /home/fbiville/Projects/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[11,7] error: Graph validation failed: You have these unused @Provider methods: [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------

Without any faulty methods listed >:(.

— Reply to this email directly or view it on GitHub https://github.com/square/dagger/issues/429.

fbiville commented 10 years ago

Hmmm, it does not seem to provide more information:

➜  vidal-rest-sdk git:(issue_1_dagger) mvn -e clean install
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] 
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder with a thread count of 4
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building vidal-rest-sdk 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ vidal-rest-sdk ---
[INFO] Deleting /home/flo/Projects/_VIDAL/vidal-rest-sdk/target
[INFO] 
[INFO] --- maven-enforcer-plugin:1.3.1:enforce (enforce-versions) @ vidal-rest-sdk ---
[INFO] 
[INFO] --- jacoco-maven-plugin:0.7.1.201405082137:prepare-agent (prepare-agent) @ vidal-rest-sdk ---
[INFO] argLine set to -javaagent:/home/flo/.m2/repository/org/jacoco/org.jacoco.agent/0.7.1.201405082137/org.jacoco.agent-0.7.1.201405082137-runtime.jar=destfile=/home/flo/Projects/_VIDAL/vidal-rest-sdk/target/jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ vidal-rest-sdk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/flo/Projects/_VIDAL/vidal-rest-sdk/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ vidal-rest-sdk ---
[INFO] Compiling 10 source files to /home/flo/Projects/_VIDAL/vidal-rest-sdk/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/flo/Projects/_VIDAL/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[12,7] error: Graph validation failed: You have these unused @Provider methods:
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.399 s (Wall Clock)
[INFO] Finished at: 2014-08-07T21:26:02+01:00
[INFO] Final Memory: 15M/87M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project vidal-rest-sdk: Compilation failure
[ERROR] /home/flo/Projects/_VIDAL/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[12,7] error: Graph validation failed: You have these unused @Provider methods:
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project vidal-rest-sdk: Compilation failure
/home/flo/Projects/_VIDAL/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[12,7] error: Graph validation failed: You have these unused @Provider methods:

    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:188)
    at org.apache.maven.lifecycle.internal.builder.multithreaded.MultiThreadedBuilder$1.call(MultiThreadedBuilder.java:184)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
/home/flo/Projects/_VIDAL/vidal-rest-sdk/src/main/java/com/vidal/rest/sdk/VidalAPI.java:[12,7] error: Graph validation failed: You have these unused @Provider methods:

    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:729)
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 11 more
[ERROR] 
[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/MojoFailureException
JakeWharton commented 10 years ago

The error should be on resourceFactory as in Dagger's eyes it's unused.

You can change your @Module declaration to fix:

@Module(injects = ResourceFactory.class)
fbiville commented 10 years ago

Hurray! That's it! I should have RTFM on Module.class.

How come the faulty method was not displayed, though? Should I keep the issue open for that?

JakeWharton commented 10 years ago

Yeah keep it open. We'll try and figure it out. Can you paste the output from mvn -v?

fbiville commented 10 years ago

Sure thing

➜  vidal-rest-sdk git:(issue_1_dagger) mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T18:37:52+01:00)
Maven home: /home/flo/Tools/maven
Java version: 1.8.0, vendor: Oracle Corporation
Java home: /home/flo/Tools/jdk1.8.0/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.11.0-26-generic", arch: "amd64", family: "unix"
heenenee commented 8 years ago

I also had this problem with maven-compiler-plugin:2.5.1, but I changed to maven-compiler-plugin:3.3 and then the unused @Provider methods were successfully displayed upon compilation failure. So it's probably some old bug in the maven-compiler-plugin failing to show multi-line error messages.

heenenee commented 8 years ago

Additionally, the unused @Provider methods are once again suppressed if <fork>true</fork> is set on the maven-compiler-plugin configuration, even on version 3.3. So there is still probably a bug regarding multi-line error messages in the maven-compiler-plugin.