Dagger dependencies when overriding graph with mock module causes NoClassDefFoundError

532 views Asked by At

I am am migrating project to dagger 1.2.2. I'd like to override some dependencies for functional tests. For that I included the dagger-compiler as a dependency of the androidTest-build(?) as well:

apt "com.squareup.dagger:dagger-compiler:$daggerVersion"
compile "com.squareup.dagger:dagger:$daggerVersion"
androidTestApt "com.squareup.dagger:dagger-compiler:$daggerVersion

Now the compiler complains that he cannot find a class (I guess because both builds now contain the transitive dependencies of dagger-compiler):

Error:Execution failed for task ':app:compileDebugAndroidTestJava'.
> java.lang.NoClassDefFoundError: javax/inject/Scope

Looking around github it seems the approach should work without manually excluding stuff.

1

There are 1 answers

0
msung On

Nevermind. Actually reading the whole buildfile helps alot.

Because of previous dependency-foo I had a directive that excluded the missing dependency explicitly:

configurations {
    androidTestCompile.exclude(group:'javax.inject')
}

Removing that fixed it.