I have added below dependency in build.gradle file. Eclipse plugin is added in build.gradle.
testCompile 'io.dropwizard:dropwizard-testing:1.2.0'
Once I run gradle eclipse command all the compile dependencies are getting added in classpath but testcompile dependencies are not getting added in classpath.
But testCompile 'io.dropwizard:dropwizard-testing:1.2.0' also has transitive dependencies like mockito. Therefore whenever I am trying to use mockito in my Junit, those are not getting compiled.
I am not sure what is the problem none of the transitive dependency of io.dropwizard:dropwizard-testing:1.2.0 is available
Looking at the dropwizard-testing dependencies here I can't see mockito in the compile scoped dependencies. It's in the test scoped dependencies but that's irrelevant, test scoped dependencies are private to that project and don't become transitive dependencies when the jar is included in another project.
Related
I am trying to add a subproject to my main one in Android Studio. I have it compiling in the build gradle of the whole project. When ever I try to build the project or compile it it gives me out this error.
Error:(9, 0) Could not find method compile() for arguments [project ':subProject.exude'] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Open File
Here is the code for the build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
compile project('subProject.exude')
I think this can be a solution to your problem. Let's say there are two modules in your project, typically named as app and lib. Now you want to use lib module in your app module. So, you need to add it to your build.gradle(app module).
compile project(':lib')
I have it compiling in the build gradle of the whole project.
It may imply two cases:
You're adding compile project('subProject.exude') to your root/project build.gradle
You're adding compile project('subProject.exude') to all of your module build.gradle
In first case, you must not add the compile project to your root build.gradle. Because it not belong there.
In second case, you're incorrectly adding the classpath to your dependencies block in your module build.gradle. This is incorrect, because you're adding classpath for dependencies:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
compile project('subProject.exude')
...
}
This is corrrect:
dependencies {
compile project('subProject.exude')
...
}
Module dependencies should not exist in root/project build.gradle.
I'm trying to compile an Android project unsuccessfully. The error message is:
Execution failed for task ':mobile:_compileAppDebug'.
java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
Here are my module's gradle dependencies in which I specify a number of libraries including google Auto:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.auto.value:auto-value:1.0-rc1'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.f2prateek.dart:dart:1.1.0'
}
When I looked at the dependencies I thought I just needed google auto value since that is where the missing method resides but adding the provided does not resolve the issue.
The project gradle file includes the retrolambda plugin
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
Can anyone help me identify which dependencies cause the compile error? Interestingly enough, when I copy the gradle files into an empty project everything runs fine.
Dagger 2.0-SNAPSHOT depends on an Auto SNAPSHOT which had an API change: https://github.com/google/dagger/issues/113
This is perfectly normal and acceptable thing for libraries which are under development. If you cannot tolerate an occasional broken build, do not depend on non-release versions in a manner that can change at any time without warning.
I ran in a similar issue. Some libary I'm using bundles Guava within the jar file.
Thus exluding this specific dependency from the apt configuration fixed the problem:
configurations {
apt.exclude module: 'artifactId-Of-Library'
}
After I added some dependencies to build.gradle
compile(
"org.springframework.boot:spring-boot-starter-web:1.1.6.RELEASE",
"org.springframework:spring-core:4.1.0.RELEASE",
"org.springframework:spring-test:4.1.0.RELEASE",
"javax.inject:javax.inject:1",
"org.mockito:mockito-all:1.9.5",
"org.quartz-scheduler:quartz:2.2.1",
"org.apache.commons:commons-lang3:3.3.2",
"com.google.guava:guava:18.0"
)
and refreshing the IntelliJ Gradle plugin, many more dependencies appear in the Gradle libs list inside "External Libs"
I suspect this is nothing to do with the plugin, but rather gradle augmenting my dependencies from somewhere else but I can't work out from where.
Just like in Maven, the dependencies you declared can have further dependencies that are declared by the package supplier (a.k.a transitive dependency management) - those will be added automatically, just like you observed.
More info here.
I need to exclude a jar from runtime dependency via Gradle.
I am getting this error:
Caused by: java.lang.IllegalStateException: Conflicting persistence unit definitions for name 'ldb-jpa': file:/D:/EricFrancis/shared/build/libs/shared.jar, file:/D:/EricFrancis/shared/build/resources/main
I'm trying to exclude the jar.
How do I tell gradle to do this?
Without more information (Gradle version, relevant parts of build script, etc.), it's hard to say. But since this isn't a Maven or Ivy dependency, I'd consider not adding it in the first place.
It turns out that I did not understand how configurations worked.
I was able to exclude the jar via:
configurations {
testRuntime {
exclude module: 'share'
}
testCompile {
exclude module: 'share'
}
}
I'm using gradle to build a groovy/java application.
This worked fine until I added a dependency to google guice 3.0.
Gradle does not add the guice jars to the compilation classpath, at least it seems so.
I get errors like these:
C:\dev\workspaces\initial>gradle -q compileJava
C:\dev\workspaces\initial\src\main\java\com\comp\test\solmon\di\GuiceDI.java:3: package com.google.inject does not exist
import com.google.inject.Guice;
^
C:\dev\workspaces\initial\src\main\java\com\comp\test\solmon\di\GuiceDI.java:4: package com.google.inject does not exist
import com.google.inject.Injector;
In my build.gradle file I have the following dependencies:
dependencies{
runtime 'com.beust:jcommander:1.27'
runtime "org.slf4j:slf4j-api:1.7.1"
runtime "ch.qos.logback:logback-classic:1.0.7"
runtime 'com.google.inject:guice:3.0'
testRuntime 'junit:junit:4+'
}
I'm developing the application in Springsource Tool Suite 2.9.2 with its gradle plugin and it uses gradles dependency management to get all dependencies. Sts manages to compile the code just fine, it's only gradle that fails.
I've tried to run the gradle compilation with the "--debug" parameter but I can not see which classpath gradle gives to the compiler.
Any ideas how to get gradle to compile my application?
You've added Guice to the runtime dependencies (i.e. the dependencies necessary to run the application, but not to compile it). Add it to the compile dependencies:
dependencies {
...
compile 'com.google.inject:guice:3.0'
}
A compile dependency is also a runtime dependency, obviously.