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
Related
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.
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
I'm trying to integrate a Log4J2 Appender to RabbitMQ in an already working and logging java application.
The application is build as a gradle project. Before the integration of spring-rabbit, the build.gradle file looked like this:
group 'Name'
version '1.18.7'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
[...]
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
[...]
}
jar {
manifest {
attributes 'Main-Class': 'the.main.Clazz'
}
}
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '2.0.2'
}
}
The log4j2.xml file, positioned in the src/resources folder, contains this (before rabbitMQ):
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="15">
<Appenders>
<Console name="STDOUT">
<PatternLayout>
<Pattern>%d [%highlight{%-6p}{STYLE=DEFAULT, noConsoleNoAnsi=true}] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</Console>
<RandomAccessFile name="ASYNC_FILE" fileName="logs/app.log" immediateFlush="false" append="true">
<PatternLayout>
<Pattern>%d [%-6p] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</RandomAccessFile>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="STDOUT"/>
</Root>
<Logger name="my.package" level="info" additivity="false">
<AppenderRef ref="ASYNC_FILE"/>
</Logger>
</Loggers>
</Configuration>
The application runs nicely, as well as from the IDE and the JAR, built with the shadowJar plugin.
Now, the mystery begins. Simply by adding the spring-rabbit dependency...
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
...logging starts to behave very strange. Started from the IDE, everything works still nice. Adding the following appender to the log4j2.xml works fine:
<RabbitMQ name="RABBIT_MQ"
host="my.host.name" port="5672" user="logger" password="logger" virtualHost="loggerhost"
exchange="logs" exchangeType="fanout" declareExchange="false"
applicationId="app-xyz" routingKeyPattern="%X{applicationId}.%c.%p"
contentType="text/plain" contentEncoding="UTF-8" generateId="true" deliveryMode="NON_PERSISTENT"
charset="UTF-8"
senderPoolSize="3" maxSenderRetries="5">
<PatternLayout>
<Pattern>%d [%-6p] %C{1}.%M(%F:%L) - %m%n%throwable</Pattern>
</PatternLayout>
</RabbitMQ>
I see the log messages delivered via the RabbitMQ server.
But when I build and run the JAR file built with :shadowJar, logging stops working. On STDOUT, I see the following:
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
ERROR StatusLogger Unrecognized format specifier [d]
ERROR StatusLogger Unrecognized conversion specifier [d] starting at position 16 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [thread]
ERROR StatusLogger Unrecognized conversion specifier [thread] starting at position 25 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [level]
ERROR StatusLogger Unrecognized conversion specifier [level] starting at position 35 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [logger]
ERROR StatusLogger Unrecognized conversion specifier [logger] starting at position 47 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [msg]
ERROR StatusLogger Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
ERROR StatusLogger Unrecognized format specifier [n]
ERROR StatusLogger Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.
When I start the application JAR with the -Dlog4j2.debug option I see a lot of messages, and some seem to say, that the configuration cannot be loaded (which is still at the same place). Here an excerpt:
DEBUG StatusLogger Using configurationFactory org.apache.logging.log4j.core.config.ConfigurationFactory$Factory#2a33fae0
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console. Set system property 'log4j2.debug' to show Log4j2 internal initialization logging.
I even used the -Dlog4j.configurationFile option, pointing directly to the XML in the file system, but the result stays the same.
Again, starting the application from the IDE and not via java -jar ... works fine. It seems to me as if the spring-rabbitmq dependency brings some extra log4j stuff that interferes with my configuration. I'm totally fishing in murky waters.
So, after a lot of research I can answer my question with the following.
It is not enough to simply add the Spring-Rabbit-MQ org.springframework.amqp:spring-rabbit dependency to let the Log4J2 configuration fail. It's the combination with another dependency, that is not listed in my example: com.fasterxml.jackson.core:jackson-databind.
To sum it up. This does not work:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
But this works (without Spring):
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
And this works (without Jackson):
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7'
compile group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE'
So the combination of Jackson and Spring breaks Log4J2. Interestingly, without Jackson, my program works as well, even if Jackson is under heavy use. Let's have a look on that, what gradle dependecies has to say:
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- org.apache.logging.log4j:log4j-api:2.10.0
+--- org.apache.logging.log4j:log4j-core:2.10.0
| \--- org.apache.logging.log4j:log4j-api:2.10.0
+--- com.lmax:disruptor:3.3.7
\--- org.springframework.amqp:spring-rabbit:2.0.2.RELEASE
+--- org.springframework.amqp:spring-amqp:2.0.2.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE
| \--- org.springframework:spring-jcl:5.0.3.RELEASE
+--- com.rabbitmq:amqp-client:5.1.2
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.8.0-alpha2
+--- com.rabbitmq:http-client:1.3.1.RELEASE
| +--- org.apache.httpcomponents:httpclient:4.5.3
| | +--- org.apache.httpcomponents:httpcore:4.4.6
| | +--- commons-logging:commons-logging:1.2
| | \--- commons-codec:commons-codec:1.9 -> 1.11
| \--- com.fasterxml.jackson.core:jackson-databind:2.9.2
| +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| \--- com.fasterxml.jackson.core:jackson-core:2.9.2
+--- org.springframework:spring-context:5.0.3.RELEASE
| +--- org.springframework:spring-aop:5.0.3.RELEASE
| | +--- org.springframework:spring-beans:5.0.3.RELEASE
| | | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| +--- org.springframework:spring-core:5.0.3.RELEASE (*)
| \--- org.springframework:spring-expression:5.0.3.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-messaging:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-tx:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-web:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
\--- org.springframework.retry:spring-retry:1.2.1.RELEASE
\--- org.springframework:spring-core:4.3.9.RELEASE -> 5.0.3.RELEASE (*)
Oh, wait, there's also a Jackson within the Spring AMQP. Well, that solves the riddle, why I can still use Jackson after removing the dependency. But this is very intransparent to me and depends on the Spring AMQP package to deliver a core dependency for me. So what I finally did is this, and it seems to work:
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.3'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
compile group: 'com.lmax', name: 'disruptor', version: '3.3.7' version: '2.12.0'
compile (group: 'org.springframework.amqp', name: 'spring-rabbit', version: '2.0.2.RELEASE') {
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
}
The dependency tree looks like the following now:
compile - Dependencies for source set 'main' (deprecated, use 'implementation ' instead).
+--- com.fasterxml.jackson.core:jackson-databind:2.9.3
| +--- com.fasterxml.jackson.core:jackson-annotations:2.9.0
| \--- com.fasterxml.jackson.core:jackson-core:2.9.3
+--- org.apache.logging.log4j:log4j-api:2.10.0
+--- org.apache.logging.log4j:log4j-core:2.10.0
| \--- org.apache.logging.log4j:log4j-api:2.10.0
+--- com.lmax:disruptor:3.3.7
\--- org.springframework.amqp:spring-rabbit:2.0.2.RELEASE
+--- org.springframework.amqp:spring-amqp:2.0.2.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE
| \--- org.springframework:spring-jcl:5.0.3.RELEASE
+--- com.rabbitmq:amqp-client:5.1.2
| \--- org.slf4j:slf4j-api:1.7.25 -> 1.8.0-alpha2
+--- com.rabbitmq:http-client:1.3.1.RELEASE
| \--- org.apache.httpcomponents:httpclient:4.5.3
| +--- org.apache.httpcomponents:httpcore:4.4.6
| +--- commons-logging:commons-logging:1.2
| \--- commons-codec:commons-codec:1.9 -> 1.11
+--- org.springframework:spring-context:5.0.3.RELEASE
| +--- org.springframework:spring-aop:5.0.3.RELEASE
| | +--- org.springframework:spring-beans:5.0.3.RELEASE
| | | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| | \--- org.springframework:spring-core:5.0.3.RELEASE (*)
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| +--- org.springframework:spring-core:5.0.3.RELEASE (*)
| \--- org.springframework:spring-expression:5.0.3.RELEASE
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-messaging:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-tx:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
+--- org.springframework:spring-web:5.0.3.RELEASE
| +--- org.springframework:spring-beans:5.0.3.RELEASE (*)
| \--- org.springframework:spring-core:5.0.3.RELEASE (*)
\--- org.springframework.retry:spring-retry:1.2.1.RELEASE
\--- org.springframework:spring-core:4.3.9.RELEASE -> 5.0.3.RELEASE (*)
I must admit that I not fully understand why the combination of two Jackson dependencies brings the Log4J2 configuration down, but now it works with this strategy:
Declare Jackson dependency explicitly (make transparent, that the application uses Jackson)
Exclude Jackson from Spring dependency
And what I really don't get: Why do all combinations work from within the IDE, but later fail when running the JAR?
This is a known issue with log4j, reported over 3 years ago. It comes up when you use the shadowjar plugin. See shadowjar issue here.
You can read both tickets to get a better understanding, but if you're looking for a point-and-click solution, just use this gradle plugin:
plugins {
id "com.github.johnrengelman.shadow" version "2.0.2"
id "de.sebastianboegl.shadow.transformer.log4j" version "2.2.0"
}
... or revert to log4j 2.0.2.
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.
I have a very pesky problem and i can't seem to find the answer anywhere.
My application throws this exception when trying to persist a #Lob:
java.lang.AbstractMethodError
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328)
at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.setCharacterStream(DelegatingPreparedStatement.java:328)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy32.setCharacterStream(Unknown Source)
at org.hibernate.type.descriptor.sql.ClobTypeDescriptor$3$1.doBind(ClobTypeDescriptor.java:83)
at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:92)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:280)
at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:275)
at org.hibernate.type.AbstractSingleColumnStandardBasicType.nullSafeSet(AbstractSingleColumnStandardBasicType.java:57)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2747)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3152)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3087)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3416)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1213)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:402)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
...(more)
I am running on Tomcat 6.0.36(also tried tomcat 7).
MySQL 4.1.22 database.
Code is compiled with jdk 7 and built with gradle.
My dependencies are:
+--- javax.mail:mail:1.4 -> 1.4.1
| \--- javax.activation:activation:1.1
+--- org.slf4j:slf4j-api:1.5.6 -> 1.6.1
+--- log4j:log4j:1.2.13 -> 1.2.16
+--- org.apache.wicket:wicket:1.4.15
| \--- org.slf4j:slf4j-api:1.5.8 -> 1.6.1
+--- org.apache.wicket:wicket-extensions:1.4.15
| +--- org.apache.wicket:wicket:1.4.15 (*)
| \--- org.slf4j:slf4j-api:1.5.8 -> 1.6.1
+--- mysql:mysql-connector-java:5.1.26
+--- com.microsoft.sqlserver:sqljdbc4:4.0
+--- com.itextpdf:itextpdf:5.4.2
+--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final -> 1.0.1.Final
+--- org.hibernate:hibernate-core:4.1.9.Final
| +--- antlr:antlr:2.7.7
| +--- org.jboss.logging:jboss-logging:3.1.0.GA
| +--- org.javassist:javassist:3.17.1-GA
| +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final
| +--- dom4j:dom4j:1.6.1
| | \--- xml-apis:xml-apis:1.0.b2
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
| \--- org.hibernate.common:hibernate-commons-annotations:4.0.1.Final
| \--- org.jboss.logging:jboss-logging:3.1.0.CR2 -> 3.1.0.GA
+--- org.hibernate:hibernate-entitymanager:4.1.9.Final
| +--- org.jboss.logging:jboss-logging:3.1.0.GA
| +--- org.javassist:javassist:3.17.1-GA
| +--- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:1.0.0.Final
| +--- dom4j:dom4j:1.6.1 (*)
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final
| +--- org.hibernate:hibernate-core:4.1.9.Final (*)
| \--- org.hibernate.common:hibernate-commons-annotations:4.0.1.Final (*)
+--- foo.bar.data-services:foor-bar-data:2.0.0.275
| +--- org.slf4j:slf4j-api:1.6.1
| +--- org.hibernate:hibernate-core:4.1.6.Final -> 4.1.9.Final (*)
| +--- org.hibernate.javax.persistence:hibernate-jpa-2.0-api::1.0.1.Final -> 1.0.1.Final
| +--- org.slf4j:slf4j-log4j12:1.6.1
| | +--- org.slf4j:slf4j-api:1.6.1
| | \--- log4j:log4j:1.2.16
| +--- log4j:log4j:1.2.16
| \--- commons-configuration:commons-configuration:1.9
| +--- commons-lang:commons-lang:2.6
| \--- commons-logging:commons-logging:1.1.1
+--- javax.transaction:jta:1.1
+--- dom4j:dom4j:1.6.1 (*)
+--- antlr:antlr:2.7.6 -> 2.7.7
+--- commons-collections:commons-collections:3.2.1
+--- commons-configuration:commons-configuration:1.9 (*)
+--- commons-dbcp:commons-dbcp:1.4
| \--- commons-pool:commons-pool:1.5.4 -> 1.5.7
+--- commons-pool:commons-pool:1.5.7
+--- commons-logging:commons-logging:1.1.1
+--- commons-dbutils:commons-dbutils:1.4
+--- commons-lang:commons-lang:2.6
+--- commons-io:commons-io:2.4
+--- org.apache.commons:commons-email:1.2
| +--- javax.mail:mail:1.4.1 (*)
| \--- javax.activation:activation:1.1
+--- javax.servlet:servlet-api:2.5
+--- javax.servlet.jsp:jsp-api:2.1
\--- org.slf4j:slf4j-log4j12:1.5.6 -> 1.6.1 (*)
So looking at the exception, it seems like the application is trying to call the tomcat-dbcp.jar in the CATALINA_BASE/lib folder. But i would expect it to call my commons-dbcp.jar in my classpath.
But frankly i'm at a loss, i tried a lot of things, but can't seem to get this working...
Thanks in advance for your help. Tell me if you need more information.
EDIT 1:
server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" logAbandoned="true" maxActive="100" maxIdle="10" maxWait="10000" name="jdbc/foo" removeAbandoned="true" removeAbandonedTimeout="300" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/foo?autoReconnect=true&dumpQueriesOnException=true" username="root" validationQuery="select 1"/>
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" logAbandoned="true" maxActive="20" maxIdle="5" maxWait="10000" name="jdbc/bar" removeAbandoned="true" removeAbandonedTimeout="300" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/bar?autoReconnect=true&dumpQueriesOnException=true" username="root" validationQuery="select 1"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
<Context docBase="foo" path="/foo" reloadable="true" source="org.eclipse.jst.j2ee.server:foo"/></Host>
</Engine>
</Service>
</Server>
The solution was to use tomcat 7. This has a version of tomcat-dbcp.jar that actually has the DelegatingPreparedStatement.setCharacterStream that the application needed.
My problem was that when i tried it on my tomcat 7 server, i still got the same error at the same place in my application. This was caused by an old version of mysql-connector-java(5.0.5 if i remember correctly) that was lingering in my tomcat lib folder due to earlier attempts to make this work. This older version apparently had precedence over my own mysql-connector-java(newest version) that i have as a dependency. Because this gave me the same exception, it seemed that it did not change anything in my situation, while it actually did.
When i figured this out, the rest was easy, my only problem was that i couldn't upgrade very easily to tomcat 7, since other applications are currently running on our tomcat 6 version in the production environment. So the solution was to copy the tomcat-dbcp.jar from a tomcat 7 dist to our tomcat 6 server and replacing the one that was already there.
Hope this will help others as well, thanks to everyone for all the help in any case!
AbstractMethodError is a subclass of LinkageError, which nearly always indicates that something is wrong with your classpath--libraries that were not compiled together are being loaded together.
Assuming your library versions line up with my momentary research...
The line that's throwing the exception is DelegatingPreparedStatement:328. It looks like this:
((PreparedStatement)_stmt).setCharacterStream(parameterIndex, reader, length);
If you click through to setCharacterStream, you see it's tagged as #since 1.6.
So, you should:
Make sure you're running under a 1.6+ VM. :)
Check that there are no other implementations of java.sql.PreparedStatement anywhere in your classpath. The way I usually do this (in a Unix-like system; you're on your own with Windows ;) is:
cd /path/to/my/jars
grep -rli 'java/sql/PreparedStatement' .
This is a brute-force way of figuring out which jars contain which classes. It works because the "directory structure" of a ZIP file is plain text, not compressed.
Good luck! :)
I am not sure but if you changed with Latest Driver
I also encountered this problem and found this question. I took the advice in the last answer, but I did not copy the tomcat-dbcp.jar, but just switched to a new version in my pom.xml and it works! Thanks for advice!
Had the same problem and solved by changing the driver library.
The implementation of DelegatingPreparedStatement delegates the setCharacterStream call to its delegate, that's why changing the driver's implementation can solve the problem (if the implementation of the delegate includes that method)