Git Product home page Git Product logo

Comments (11)

stephanenicolas avatar stephanenicolas commented on April 28, 2024

For me it works when adding dagger 2 with both apt and testCompile scopes.

BTW, it would be great if we could have an example of testing with Dagger 2. It's not obvious at all to figure out how module can be overiden.

from dagger.

westward avatar westward commented on April 28, 2024

Can you please provide an example project? I tried to add dagger compiler as a testCompile dependency but without success.

from dagger.

twelve17 avatar twelve17 commented on April 28, 2024

I'm also running into this issue. An example project or a few pointers would be helpful. Thanks!

from dagger.

sockeqwe avatar sockeqwe commented on April 28, 2024

That build.gradle script works for me (with android apt plugin):

dependencies {
    apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
    compile 'com.google.dagger:dagger:2.0-SNAPSHOT'

    // Additional for unit tests
    testProvided 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
}

from dagger.

westward avatar westward commented on April 28, 2024

Can you please provide an example project? I would like to see the whole project configuration related to JUnit tests.

from dagger.

cgruber avatar cgruber commented on April 28, 2024

Our recommendation for Android Studio is to use https://bitbucket.org/hvisser/android-apt as described above. I'm going to close this. If you are still encountering it when using the apt plugin, and after updating all dependencies, please re-open this, but point to either a github repo with an example project, or a gist containing a failing test, or something so we can reproduce this.

from dagger.

westward avatar westward commented on April 28, 2024

Here is the AndroidStudio example project: https://github.com/westward/Dagger2Test
It contains the single JUnit file named DummyControllerTest.java with code that should create a Component. I tried "testProvided", "testCompile" directives in build.gradle, both variants without success.
Thanks!
P.S. Christian, I cannot re-open my issue. Please do it by yourself if it's possible.

from dagger.

stephanenicolas avatar stephanenicolas commented on April 28, 2024

@cgruber why use android apt plugin ? Gradle and Android Studio are supposed to have annotation processor support out of the box, no ?

from dagger.

tbroyer avatar tbroyer commented on April 28, 2024

@stephanenicolas javac does annotation processing out of the box (unless told otherwise) by looking for processors in the classpath. So in that sense, yes, Gradle supports annotation processing out of the box. But Gradle is missing one thing: dependencies that you need when compiling but not at runtime (such as annotation processors; you don't want to package them into your application). Additionally, ideally, you'd want to be explicit about your processorpath, rather than just put annotation processors in the classpath: the processorpath is usually much smaller than the classpath so processor discovery is faster, but more importantly you know you're not bringing in an annotation processor that you didn't mean to use (for example, antlr' includes its own annotation processor: antlr/antlr4#487)

So you want an apt (or whatever its name) configuration that ends up filling javac's -processorpath, independently of the classpath. android-apt does just that, for Android builds.

from dagger.

JakeWharton avatar JakeWharton commented on April 28, 2024

And it also makes the generated sources visible to the IDE automatically.

from dagger.

westward avatar westward commented on April 28, 2024

OK guys, what's wrong with my example project? What I've missing? I can't use Dagger2 in tests, I didn't configured project well, something else? Any advice or hint please!

from dagger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.