import extra project which is one level above of main gradle project file - java

I have a big project which depends on an another project. My git structure is following:
/gitRepository
|
|--> /ConfigFacade
| |
| |--> /ejbModule/
| | --> META-INF/
| | --> com/myApp/com/name/myClass.java
|--> /myMainApp
| |
| |--> /src/
| | --> main/java/com/name/allJavaFiles.java
| |--> build.gradle
How should I add correctly ConfigFacade project to my gradle file?
I tried something like that but it doesnt work
dependencies {
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
providedCompile group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version: '2.3.1'
providedCompile project(':ConfigFacade')
}
How gradle should import another project one level above where gradle file is?

Create a settings.gradle file next to your build.gradle file with the following content:
includeFlat 'ConfigFacade'
That should do the trick. See also the docs of includeFlat.

Related

Issues with converting Eclipse Groovy project to Gradle project

I have an existing Groovy project, created with the Eclipse IDE, defined to be:
SposZohoMergeScript
-- src
-- com.xxx.sposZohoMergeScript
-- com.xxx.sposZohoMergeScript.constants
-- com.xxx.sposZohoMergeScript.factories
-- com.xxx.sposZohoMergeScript.io
-- com.xxx.sposZohoMergeScript.mergers
-- com.xxx.sposZohoMergeScript.models
-- com.xxx.sposZohoMergeScript.utils
I have been manually downloading, vetting, and bringing into the project build path the individual JAR files per each library and dependency... Not to mention there's no built-in system for testing... How am I supposed to keep working like this?!
It's time to bring in Gradle!
I try the Gradle plugin, and it goes sideways pretty much immediately...
I run the build setup init step, and it runs forever...even if I go to sleep, wake up a few hours later, and check back on it, it's still there...
I close the Eclipse IDE, open up the BASH, on the SposZohoMergeScript folder, run gradle init myself, and it re-fucktors my project.
I try to set it up as basic project:
I then create the build.gradle:
/*
* This file was generated by the Gradle 'init' task.
*
* This is a general purpose Gradle build.
* Learn more about Gradle by exploring our samples at https://docs.gradle.org/7.2/samples
*/
plugins {
id 'java'
id 'groovy'
}
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.apache.poi/poi
implementation 'org.apache.poi:poi:5.2.3'
// https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml
implementation 'org.apache.poi:poi-ooxml:5.2.3'
}
I then do a gradle build, which runs successfully. After that, I open up the Eclipse, and not only do I see my folder structure all messed up...
but when I go to, for example, use the keyboard shortcuts to create a constructor, it gives me error, and the highlighter/IntelliSense can't make sense of previously-working code I have written:
I run gradle dependencies for the project, and this is what I get:
> Task :dependencies
------------------------------------------------------------
Root project 'SposZohoMergeScript'
------------------------------------------------------------
annotationProcessor - Annotation processors and their dependencies for source set 'main'.
No dependencies
apiElements - API elements for main. (n)
No dependencies
archives - Configuration for archive artifacts. (n)
No dependencies
compileClasspath - Compile classpath for source set 'main'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| \--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 (*)
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| \--- org.apache.xmlbeans:xmlbeans:5.1.1
| \--- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.commons:commons-collections4:4.4
compileOnly - Compile only dependencies for source set 'main'. (n)
No dependencies
default - Configuration for default artifacts. (n)
No dependencies
implementation - Implementation only dependencies for source set 'main'. (n)
+--- org.apache.poi:poi:5.2.3 (n)
\--- org.apache.poi:poi-ooxml:5.2.3 (n)
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| \--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 (*)
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| \--- org.apache.xmlbeans:xmlbeans:5.1.1
| \--- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.commons:commons-collections4:4.4
runtimeElements - Elements of runtime for main. (n)
No dependencies
runtimeOnly - Runtime only dependencies for source set 'main'. (n)
No dependencies
testAnnotationProcessor - Annotation processors and their dependencies for source set 'test'.
No dependencies
testCompileClasspath - Compile classpath for source set 'test'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| \--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 (*)
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| \--- org.apache.xmlbeans:xmlbeans:5.1.1
| \--- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.commons:commons-collections4:4.4
testCompileOnly - Compile only dependencies for source set 'test'. (n)
No dependencies
testImplementation - Implementation only dependencies for source set 'test'. (n)
No dependencies
testRuntimeClasspath - Runtime classpath of source set 'test'.
+--- org.apache.poi:poi:5.2.3
| +--- commons-codec:commons-codec:1.15
| +--- org.apache.commons:commons-collections4:4.4
| +--- org.apache.commons:commons-math3:3.6.1
| +--- commons-io:commons-io:2.11.0
| +--- com.zaxxer:SparseBitSet:1.2
| \--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.poi:poi-ooxml:5.2.3
+--- org.apache.poi:poi:5.2.3 (*)
+--- org.apache.poi:poi-ooxml-lite:5.2.3
| \--- org.apache.xmlbeans:xmlbeans:5.1.1
| \--- org.apache.logging.log4j:log4j-api:2.18.0
+--- org.apache.xmlbeans:xmlbeans:5.1.1 (*)
+--- org.apache.commons:commons-compress:1.21
+--- commons-io:commons-io:2.11.0
+--- com.github.virtuald:curvesapi:1.07
+--- org.apache.logging.log4j:log4j-api:2.18.0
\--- org.apache.commons:commons-collections4:4.4
testRuntimeOnly - Runtime only dependencies for source set 'test'. (n)
No dependencies
(*) - dependencies omitted (listed previously)
(n) - Not resolved (configuration is not meant to be resolved)
A web-based, searchable dependency report is available by adding the --scan option.
BUILD SUCCESSFUL in 2s
1 actionable task: 1 executed
I am using Eclipse IDE Version: 2022-09 (4.25.0), Build id: 20220908-1902 , and Gradle 7.2, on Windows 10 64-bit computer .
What can I do to get Gradle working with the Eclipse?
Based on your screenshot alone, the directory structure is not correct for Gradle.
By convention, the Java and Groovy plugin configure their source sets to be src/main/java and src/main/groovy:
https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_project_layout
https://docs.gradle.org/current/userguide/groovy_plugin.html#sec:groovy_project_layout
Your screenshot shows that you only have src/ followed by your code/package. Move your code to be under src/main/groovy/ for Groovy code and src/main/java for Java code.
To correct your project structure in Eclipse do the following:
Right-click the project and choose New > Folder and create the folder src/main/java
Move the folder src/com into src/main/java
Right-click src/main/java and choose Build Path > Use As Source Folder

Gradle multi-module project compilation fails with "classNotFoundExceptions" from dependencies mentioned in sub-modules

I have a multi-module setup for a Java project with following structure.
mainApp
|--> core-module
| |--> src
| |--> build.gradle
|--> implementation group: 'org.apache.axis2', name: 'axis2-kernel', version: '1.7.8'
|--> implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.13'
|--> implementation files('libs/some_local.jar')
|--> compile project(":lib-module")
|--> compile project(":lib-another-module")
|--> ...
|
|--> lib-module
| |--> src
| |--> build.gradle
|--> implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
|--> implementation files('libs/another_local.jar')
|--> ...
|--> lib-another-module
| |--> src
| |--> build.gradle
|--> implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
|--> implementation files('libs/another_local.jar')
|--> ...
|
|--> settings.gradle
|--> build.gradle
|--> gradle.properties
In mainApp/build.gradle file I have a 'mentioned' sub-modules as
sourceSets {
main {
java {
srcDirs project('core-module').file("src")
srcDirs project('lib-module').file("src")
srcDirs project('lib-another-module').file("src")
}
}
}
If I build individual sub-module it get compiled successfully but when I run ./gradlew compileJava at root , it fails with classNotFoundExceptions from the jars which I've already mentioned in sub-modules
> Task :core-module:compileJava
//successful
> Task :lib-module:compileJava
//successful
> Task :lib-another-module:compileJava
//successful
> Task :compileJava
/.../core-module/src/java/../OAuthUtils.java:12: error: package org.apache.http does not exist
import org.apache.http.Header;
...
//FAILED!
Here ./gradlew core-module:compileJava works perfectly but compilation fails when invoked from root.
How shall I deal with it?
Is it because of some local jars referred from file-system?
EDIT
I found that the compilation of root sourceSets{} which is pointing to child sub-module is failing and individual sub-module compilation is successful.
But, I need this sourceSets{} for creating one monolithic jar of all sub-module
Note:- I'm not creating fatJar or shadedJar here, But I need to include all packages from all sub-modules without dependency jars.
This how I'm successfully able to create the one monolithic jar from all sub-module
jar {
dependsOn compileJava
manifest {
def userName = System.properties['user.name']
def javaVersion = JavaVersion.current()
attributes 'Manifest-Version' : "1.0"
attributes 'Built-By' : userName
attributes 'Created-By' : "Java Version: " + javaVersion
}
destinationDir(file("$buildDir/image"))
baseName(jarName)
from project('core-module').sourceSets.main.output.classesDirs
from project('lib-module').sourceSets.main.output.classesDirs
from project('lib-another-module').sourceSets.main.output.classesDirs
}

Spring Boot/Gradle/Logback: bootRun fails with "Failed to instantiate [ch.qos.logback.classic.LoggerContext]": java.lang.AbstractMethodError:

In a new Spring Boot application, when I gradle bootRun, I see this error:
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
java.lang.AbstractMethodError: ch.qos.logback.classic.pattern.EnsureExceptionHandling.process(Lch/qos/logback/core/Context;Lch/qos/logback/core/pattern/Converter;)V
at ch.qos.logback.core.pattern.PatternLayoutBase.start(PatternLayoutBase.java:86)
at ch.qos.logback.classic.encoder.PatternLayoutEncoder.start(PatternLayoutEncoder.java:28)
at ch.qos.logback.classic.BasicConfigurator.configure(BasicConfigurator.java:50)
at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:164)
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
at com.klarna.risk.decision.application.RiskDecisionApplication.<clinit>(RiskDecisionApplication.java:14)
build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'http://repo.spring.io/release' }
}
dependencies {
classpath 'org.gretty:gretty:+'
}
}
plugins {
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'war'
}
apply plugin: 'org.gretty'
repositories {
jcenter()
maven { url 'http://repo.spring.io/release' }
}
gretty { // for Gradle 4.0+
springBoot = true
springBootVersion = '2.1.9.RELEASE'
httpPort = 8080
contextPath = ''
}
repositories {
mavenCentral()
}
group = 'com.example.newapp'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceSets {
test {
java {
srcDirs = ['src/test/java', 'src/api-test/java']
}
}
}
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation "org.springframework.boot:spring-boot-starter-jetty"
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
What is the problem?
When I check with gradle dependencyInsight --dependency logback, I see:
> Task :dependencyInsight
ch.qos.logback:logback-classic:1.1.3 (selected by rule)
variant "compile" [
org.gradle.status = release (not requested)
org.gradle.usage = java-api
org.gradle.libraryelements = jar (compatible with: classes)
org.gradle.category = library (not requested)
Requested attributes not found in the selected variant:
org.gradle.dependency.bundling = external
org.gradle.jvm.version = 8
]
ch.qos.logback:logback-classic:1.1.3
\--- compileClasspath
ch.qos.logback:logback-classic:1.2.3 -> 1.1.3
\--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE
\--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE
+--- compileClasspath (requested org.springframework.boot:spring-boot-starter)
+--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE
| +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)
| \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE
| \--- compileClasspath
+--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE
| +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)
| \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE
| \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)
\--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE
\--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE (*)
ch.qos.logback:logback-core:1.2.3 (selected by rule)
variant "compile" [
org.gradle.status = release (not requested)
org.gradle.usage = java-api
org.gradle.libraryelements = jar (compatible with: classes)
org.gradle.category = library (not requested)
Requested attributes not found in the selected variant:
org.gradle.dependency.bundling = external
org.gradle.jvm.version = 8
]
ch.qos.logback:logback-core:1.1.3 -> 1.2.3
\--- ch.qos.logback:logback-classic:1.1.3
+--- compileClasspath
\--- org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE (requested ch.qos.logback:logback-classic:1.2.3)
\--- org.springframework.boot:spring-boot-starter:2.1.9.RELEASE
+--- compileClasspath (requested org.springframework.boot:spring-boot-starter)
+--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE
| +--- compileClasspath (requested org.springframework.boot:spring-boot-starter-web)
| \--- org.springframework.boot:spring-boot-starter-websocket:2.1.9.RELEASE
| \--- compileClasspath
+--- org.springframework.boot:spring-boot-starter-json:2.1.9.RELEASE
| +--- org.springframework.boot:spring-boot-starter-web:2.1.9.RELEASE (*)
| \--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE
| \--- compileClasspath (requested org.springframework.boot:spring-boot-starter-jersey)
\--- org.springframework.boot:spring-boot-starter-validation:2.1.9.RELEASE
\--- org.springframework.boot:spring-boot-starter-jersey:2.1.9.RELEASE (*)
(*) - dependencies omitted (listed previously)
A web-based, searchable dependency report is available by adding the --scan option.
Seems that Spring Boot 2.1.9 is using org.springframework.boot:spring-boot-starter-logging:2.1.9.RELEASE, which uses logback-classic:1.1.3. Somewhere in the Google tells me that Spring Boot dependency management has a bug which permits distinct versions of logback-core and logback-classic here and causes conflicts.
I added the dependency of logback-core:1.1.3 and the problem is gone.
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.1.3'
If you face the same problem, be sure to check the version of logback used in Spring Boot.
Kindly try to add these 3 dependencies in your pom.xml file. It worked for me..
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.2.3</version>
<scope>compile</scope>
</dependency>
Create an logback-test.xml file under resources file along with logback.xml and initialise this new file with just . and it should work

error with gcm while generating signed apk android

I got an error while generating signed apk in android studio
Error:Execution failed for task ':AppName:transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/common/internal/zzv$zza$zza.class
Gradle....
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "myApp"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile 'org.altbeacon:android-beacon-library:2.1.4'
compile project(':qRCodeReaderViewlib')
compile project(':viewpagerindicator')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services-maps:9.0.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile files('libs/android-query-full.0.26.7.jar')
//compile files('libs/gcm.jar')
compile files('libs/mint-4.4.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.firebase:firebase-messaging:9.4.0'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
Any help ? Thanks in advance..
You are using different versions of play services.this usually ends up in error.change
compile 'com.google.android.gms:play-services-maps:9.0.0'
to
compile 'com.google.android.gms:play-services-maps:9.4.0'
https://stackoverflow.com/a/38201741/3111083.
This is a case of duplicate or transitive dependencies in your gradle. To check where the duplication is arising from, always construct the dependency tree first.
This is done via the allDependencies gradle task. On the right hand bar in your Android Studio, click Gradle > app > Tasks > Android > androidDependencies. Your gradle console will now have your dependency tree outputted in the form of
| +--- pm.tin.tincan.android:sectioned-recyclerview:1.0
| +--- com.crashlytics.sdk.android:crashlytics:2.5.1
| | +--- io.fabric.sdk.android:fabric:1.3.5
| | +--- com.crashlytics.sdk.android:crashlytics-core:2.3.4
| | | +--- io.fabric.sdk.android:fabric:1.3.5
| | | \--- com.crashlytics.sdk.android:answers:1.3.1
| | | \--- io.fabric.sdk.android:fabric:1.3.5
| | +--- com.crashlytics.sdk.android:beta:1.1.3
| | | \--- io.fabric.sdk.android:fabric:1.3.5
| | \--- com.crashlytics.sdk.android:answers:1.3.1
| | \--- io.fabric.sdk.android:fabric:1.3.5
| +--- com.google.android.gms:play-services-gcm:8.4.0
| | +--- com.google.android.gms:play-services-base:8.4.0
| | | \--- com.google.android.gms:play-services-basement:8.4.0
| | \--- com.google.android.gms:play-services-measurement:8.4.0
| | \--- com.google.android.gms:play-services-basement:8.4.0
| +--- de.hdodenhof:circleimageview:2.0.0
Here, check for conflicting library versions everywhere in your tree.
Once that's sorted, you can exclude conflicting deps by saying
compile("com.crashlytics.sdk.android:crashlytics:2.5.1") {
transitive = true
exclude group: "com.android.support" // Conflicting dep removed here
}

Android tests build error: Multiple dex files define Landroid/support/test/BuildConfig

I'm trying to add Espresso 2 to my project (which also has lots of other dependencies), but I'm hitting this error when trying to run tests:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/test/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
...
The non-test build works fine.
Does anybody have any tips on the best way to debug this?
I've tried running ./gradlew -q :<my_project>:dependencies, but I can't see any obvious problems (though I don't know much about interpreting its output):
<snip>
androidTestCompile - Classpath for compiling the androidTest sources.
+--- com.squareup.spoon:spoon-client:1.1.2
+--- com.google.dexmaker:dexmaker-mockito:1.0
| +--- com.google.dexmaker:dexmaker:1.0
| \--- org.mockito:mockito-core:1.9.5
| +--- org.hamcrest:hamcrest-core:1.1
| \--- org.objenesis:objenesis:1.0
+--- com.google.dexmaker:dexmaker:1.0
+--- org.mockito:mockito-core:1.9.5 (*)
+--- com.jayway.android.robotium:robotium-solo:5.3.1
+--- com.android.support.test.espresso:espresso-core:2.0
| +--- com.squareup:javawriter:2.1.1
| +--- org.hamcrest:hamcrest-integration:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- org.hamcrest:hamcrest-library:1.1
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- javax.inject:javax.inject:1
| +--- com.android.support.test.espresso:espresso-idling-resource:2.0
| +--- com.android.support.test:testing-support-lib:0.1
| | \--- junit:junit-dep:4.10
| | \--- org.hamcrest:hamcrest-core:1.1
| +--- com.google.code.findbugs:jsr305:2.0.1
| +--- javax.annotation:javax.annotation-api:1.2
| \--- org.hamcrest:hamcrest-core:1.1
\--- com.android.support.test:runner:0.2
+--- junit:junit-dep:4.10 (*)
+--- com.android.support.test:exposed-instrumentation-api-publish:0.2
\--- com.android.support:support-annotations:22.0.0
<snip>
compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:22.1.0
| \--- com.android.support:support-v4:22.1.0
| \--- com.android.support:support-annotations:22.1.0
+--- com.android.support:support-v4:22.1.0 (*)
+--- com.afollestad:material-dialogs:0.7.2.4
| +--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
| +--- com.android.support:appcompat-v7:22.0.0 -> 22.1.0 (*)
| +--- com.android.support:support-annotations:22.0.0 -> 22.1.0
| \--- com.android.support:recyclerview-v7:22.0.0
| +--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
| \--- com.android.support:support-annotations:22.0.0 -> 22.1.0
+--- com.google.android.gms:play-services-base:7.0.0
| \--- com.android.support:support-v4:22.0.0 -> 22.1.0 (*)
+--- com.google.android.gms:play-services-gcm:7.0.0
| \--- com.google.android.gms:play-services-base:7.0.0 (*)
+--- de.greenrobot:greendao:1.3.7
+--- de.greenrobot:eventbus:2.2.0
+--- com.squareup.wire:wire-runtime:1.4.0
| \--- com.squareup.okio:okio:0.6.0 -> 1.0.1
+--- com.squareup.okio:okio:1.0.1
+--- com.squareup.okhttp:okhttp-urlconnection:2.0.0
| \--- com.squareup.okhttp:okhttp:2.0.0
| \--- com.squareup.okio:okio:1.0.0 -> 1.0.1
+--- com.squareup.retrofit:retrofit:1.6.0
| \--- com.google.code.gson:gson:2.2.4
+--- com.squareup.retrofit:converter-wire:1.6.0
| +--- com.squareup.retrofit:retrofit:1.6.0 (*)
| \--- com.squareup.wire:wire-runtime:1.2.0 -> 1.4.0 (*)
+--- com.squareup.okhttp:okhttp:2.0.0 (*)
+--- com.squareup.picasso:picasso:2.4.0
+--- com.path:android-priority-jobqueue:1.1.2
| \--- com.google.android:android:2.2.1
| +--- commons-logging:commons-logging:1.1.1
| +--- org.apache.httpcomponents:httpclient:4.0.1
| | +--- org.apache.httpcomponents:httpcore:4.0.1
| | +--- commons-logging:commons-logging:1.1.1
| | \--- commons-codec:commons-codec:1.3
| +--- org.khronos:opengl-api:gl1.1-android-2.1_r1
| +--- xerces:xmlParserAPIs:2.6.2
| +--- xpp3:xpp3:1.1.4c
| \--- org.json:json:20080701
+--- com.netflix.rxjava:rxjava-android:0.16.1
| \--- com.netflix.rxjava:rxjava-core:0.16.1
+--- com.nineoldandroids:library:2.4.0
+--- it.sephiroth.android.library.horizontallistview:hlistview:1.2.2
| \--- com.android.support:support-v4:19.1.+ -> 22.1.0 (*)
+--- com.joooonho:selectableroundedimageview:1.0.1
+--- com.crashlytics.sdk.android:crashlytics:2.0.1
| +--- com.crashlytics.sdk.android:answers:1.0.1
| | \--- io.fabric.sdk.android:fabric:1.0.1
| +--- io.fabric.sdk.android:fabric:1.0.1
| \--- com.crashlytics.sdk.android:beta:1.0.1
| \--- io.fabric.sdk.android:fabric:1.0.1
+--- com.mixpanel.android:mixpanel-android:4.5.3
\--- com.facebook.android:facebook-android-sdk:4.0.0
+--- com.android.support:support-v4:[21,22) -> 22.1.0 (*)
\--- com.parse.bolts:bolts-android:1.1.4
<snip>
I've also tried searching subfolders of my build/intermediates directory, but I couldn't see any smoking guns (though I'm not sure I was searching all the external dependency JARs in the right way).
Here is the dependency section of my build.gradle:
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.android.support:support-v4:22.1.0'
compile 'com.afollestad:material-dialogs:0.7.2.4'
compile 'com.google.android.gms:play-services-base:7.0.0'
compile 'com.google.android.gms:play-services-gcm:7.0.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'de.greenrobot:eventbus:2.2.0'
compile 'com.squareup.wire:wire-runtime:1.4.0'
compile 'com.squareup.okio:okio:1.0.1'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.retrofit:retrofit:1.6.0'
compile 'com.squareup.retrofit:converter-wire:1.6.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.path:android-priority-jobqueue:1.1.2'
compile 'com.netflix.rxjava:rxjava-android:0.16.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'
compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile('com.crashlytics.sdk.android:crashlytics:2.0.1#aar') {
transitive = true;
}
compile "com.mixpanel.android:mixpanel-android:4.5.3"
compile "com.facebook.android:facebook-android-sdk:4.0.0"
// For the Rollbar JAR, as it is not available in Maven central
compile fileTree(dir: 'libs', include: '*.jar')
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.3.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
androidTestCompile 'com.android.support.test:runner:0.2'
}
Update: when I update from com.android.tools.build:gradle:1.0.0 to com.android.tools.build:gradle:1.1.1, I get this warning:
Warning:Conflict with dependency 'com.android.support:support-annotations'. Resolved versions for app (22.1.0) and test app (22.0.0) differ.
Update (9/07/2015):
You can continue to work with 22.2.1 if you use the following excludes:
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:runner:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
}
If you depend on espresso-contrib, you need the exclude as well.
Update (8/03/2015):
With support library 22.2.1, the dependencies are broken again; please don't upgrade to 22.2.1 until a new runner is released.
Update (6/04/2015):
With the latest release of runner 0.3 and rules 0.3, this answer is no longer needed. You can simply use
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile 'com.android.support.test:rules:0.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
with latest support libraries. (22.2.0 as of this writing)
Update (5/30/2015):
compile 'com.android.support:appcompat-v7:22.2.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2'
// com.android.support.test:testing-support-lib:0.1 // <-- causes issue
Update (4/24/2015):
The problem is that com.android.support:support-v4:22.1.1 is clashing with com.android.support.test:runner:0.2 (as that depends on com.android.support:support-v4:22.0.0).
com.android.support.test.espresso:espresso-core:2.1 has a dependency on com.android.support.test:runner:0.2, so it also causes the same error.
So, this combination will work:
compile 'com.android.support:support-v4:22.0.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
...and so will this one (without 'com.android.support.test:runner:0.2'):
compile 'com.android.support:support-v4:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
Original Answer:
Contrary to what the Espresso documentation says, you should remove this dependency:
androidTestCompile 'com.android.support.test:runner:0.2'
As it is the cause for library version conflict.
You should also update to Android gradle plugin 1.1.1, as that version will tell you the exact version conflict, which is useful in this case.
One other useful tip is how to force dependency resolution to a specific version.
Here is one way:
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.0.0'
}
...and here is another:
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'com.android.support') {
details.useVersion '22.0.0'
}
}
}
Using either of these with com.android.support.test.espresso:espresso-core:2.1 should work.
See the Forcing consistent version for a group of libraries section in the Gradle documentation for more information.
I recently ran into this error after we enabled incremental gradle builds.
dexOptions {
javaMaxHeapSize "2g"
incremental true
}
This was resolved by disabling predexing libraries.
dexOptions {
javaMaxHeapSize "2g"
incremental true
preDexLibraries = false
}
My solution:
compile 'com.android.support:appcompat-v7:22.1.0'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.1'
androidTestCompile 'com.android.support:support-annotations:22.1.0'
androidTestCompile 'com.android.support.test:runner:0.2'
+
android {
packagingOptions {
exclude 'LICENSE.txt'
}
}
I got this error trying to set up Espresso as well. Try using
espresso-contrib:2.1, not 2.0
Try excluding the following from espresso (one at a time):
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
exclude group: 'javax.inject'
exclude group: 'com.google.code.findbugs'
exclude group: 'com.android.support', module: 'support-annotations'
}
Probably need to do the same with runner
According to this bug report, you can also use resolutionStrategy:
allprojects {
repositories {
mavenCentral()
maven {
url 'http://download.crashlytics.com/maven'
}
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:22.2.0'
}
}
This is the solution that worked for me and allowed me to use the most recent version of appcompat-v7 and appcompat-v4.

Categories