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.
Related
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
I am upgrading my grails 2.5.x application to grails 4.0.8
After adding everything and all dependencies i am getting this error.
java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
I found various similar post on the same error but none seems to work. This error seems to be very user specific.
My stacktrace looks like this->
C:\Java-11.0.8_10-winx64\bin\java.exe -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -XX:CICompilerCount=3 -Djline.WindowsTerminal.directConsole=false -Dfile.encoding=UTF-8 #C:\Users\username\AppData\Local\Temp\idea_arg_file229552621 org.grails.cli.GrailsCli run-app --plain-output
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
|Running application...
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.reflect.AnnotatedElement.lambda$getDeclaredAnnotationsByType$0(java.lang.annotation.Annotation,java.lang.annotation.Annotation)
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: The hasOne property in class [com.ideas.cma.gft.RateSourceGftServerDetails] should have an initial expression of type Map or Class.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/C:/Users/idnsuv/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy/2.5.14/f0a005fb21e7bd9b7ebf04cd2ecda0fc8f3be59d/groovy-2.5.14.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-03-05 09:49:39.795 ERROR --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grailsApplicationPostProcessor' defined in com.ideas.cma.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:514)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:319)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:118)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:312)
at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
at com.ideas.cma.Application.main(Application.groovy:11)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
... 25 common frames omitted
Caused by: org.grails.core.exceptions.GrailsRuntimeException: Error instantiated artefact class [class com.ideas.cma.excelExport.myTasks.MyTeamTaskExcelExportService] of type [class org.grails.core.DefaultGrailsServiceClass]: InvocationTargetException
at grails.core.ArtefactHandlerAdapter.newArtefactClass(ArtefactHandlerAdapter.java:170)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:812)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:504)
at grails.core.DefaultGrailsApplication.addArtefact(DefaultGrailsApplication.java:775)
at grails.boot.config.GrailsApplicationPostProcessor.performGrailsInitializationSequence(GrailsApplicationPostProcessor.groovy:112)
at grails.boot.config.GrailsApplicationPostProcessor.initializeGrailsApplication(GrailsApplicationPostProcessor.groovy:94)
at grails.boot.config.GrailsApplicationPostProcessor.setApplicationContext(GrailsApplicationPostProcessor.groovy:231)
at grails.boot.config.GrailsApplicationPostProcessor.<init>(GrailsApplicationPostProcessor.groovy:78)
at grails.boot.config.GrailsAutoConfiguration.grailsApplicationPostProcessor(GrailsAutoConfiguration.groovy:68)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 26 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at grails.core.ArtefactHandlerAdapter.newArtefactClass(ArtefactHandlerAdapter.java:161)
... 39 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/apache/poi/ss/usermodel/Workbook
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.privateGetPublicMethods(Class.java:3191)
at java.base/java.lang.Class.getMethods(Class.java:1904)
at java.desktop/com.sun.beans.introspect.MethodInfo.get(MethodInfo.java:70)
at java.desktop/com.sun.beans.introspect.ClassInfo.getMethods(ClassInfo.java:71)
at java.desktop/java.beans.Introspector.getTargetMethodInfo(Introspector.java:1046)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:462)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:205)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:293)
at java.desktop/java.beans.Introspector.<init>(Introspector.java:443)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:205)
at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3356)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at groovy.lang.MetaClassImpl.addProperties(MetaClassImpl.java:3354)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3331)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:287)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:329)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:272)
at org.grails.datastore.mapping.reflect.ClassPropertyFetcher.getStaticPropertyValue(ClassPropertyFetcher.java:176)
at org.grails.core.AbstractGrailsClass.getStaticPropertyValue(AbstractGrailsClass.java:239)
at org.grails.core.DefaultGrailsServiceClass.<init>(DefaultGrailsServiceClass.java:34)
... 44 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.apache.poi.ss.usermodel.Workbook
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at org.springframework.boot.devtools.restart.classloader.RestartClassLoader.loadClass(RestartClassLoader.java:144)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 66 common frames omitted
Using java 11 with grails 4.0.8 (grails 4 uses gradle build) in IntelliJ idea.
Running in java 8 doesn't make a difference.
Using pathingJar in gradle as such huge dependencies give the file path/ extention too long error in windows 10
build.gradle(minified)--
buildscript {
repositories {
maven { url "http://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0"
classpath "org.grails.plugins:hibernate5:7.0.4"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.2.4"
}
}
version "0.1"
group "com.domain.projectname"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.erdi.webdriver-binaries"
apply plugin:"com.bertramlabs.asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenCentral()
maven { url "http://repo.grails.org/grails/core" }
//for external-config
maven { url "https://oss.jfrog.org/repo/" }
maven { url "https://repo.grails.org/grails/plugins" }
flatDir {
dirs 'lib'
}
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
developmentOnly("org.springframework.boot:spring-boot-devtools")
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core:4.0.8"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core"
compile "org.grails.plugins:gsp"
compileOnly "io.micronaut:micronaut-inject-groovy"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2:1.4.199"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "javax.xml.bind:jaxb-api:2.3.1"
runtime "com.bertramlabs.plugins:asset-pipeline-grails"
testCompile "io.micronaut:micronaut-inject-groovy"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.mockito:mockito-core"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.seleniumhq.selenium:selenium-remote-driver"
testCompile "org.seleniumhq.selenium:selenium-api:3.14.0"
testCompile "org.seleniumhq.selenium:selenium-support:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:3.14.0"
testRuntime "org.seleniumhq.selenium:selenium-firefox-driver:3.14.0"
// User added
compile 'org.grails.plugins:external-config:2.0.0'
//Below are the dependencies which are situated in /lib folder as .jar
compile name: 'activation'
compile name: 'axis'
compile name: 'cma-common'
compile name: 'commons-collections4-4.1'
compile name: 'commons-discovery-0.2'
compile name: 'commons-logging-1.0.4'
compile name: 'concurrent'
compile name: 'CSVUpload'
compile name: 'DynamicJasper-3.0.4'
compile name: 'hibernate-entitymanager'
compile name: 'hibernate-search'
compile name: 'hibernate-validator'
compile name: 'ideas-intf-integration'
compile name: 'iText-2.1.4'
compile name: 'jasperreports-3.1.4'
compile name: 'jaxb1-impl'
compile name: 'jaxb-impl'
compile name: 'jaxb-xjc'
compile name: 'jaxrpc'
compile name: 'jbossall-ideas-client'
compile name: 'jboss-aop-jdk50'
compile name: 'jboss-jaxws'
compile name: 'jboss-messaging-client'
compile name: 'jboss-remoting'
compile name: 'jboss-saaj'
compile name: 'jboss-serialization'
compile name: 'jbossws-client'
compile name: 'jbossws-common'
compile name: 'jbossws-spi'
compile name: 'jboss-xml-binding'
compile name: 'jms'
compile name: 'jnp-client'
compile name: 'jsr173_1.0_api'
compile name: 'lucene-core'
compile name: 'mail'
compile name: 'mysql-connector-java-5.1.20'
compile name: 'policy'
compile name: 'saaj'
compile name: 'sfdcws'
compile name: 'sqljdbc4-1'
compile name: 'trove'
compile name: 'ooxml-schemas-1.3'
compile name: 'poi-3.17'
compile name: 'poi-ooxml-3.17'
compile name: 'poi-ooxml-schemas-3.17'
compile name: 'wsdl4j-1.5.1'
compile name: 'xercesImpl'
compile name: 'xmlbeans-3.1.0'
compile name: 'xpp3_min-1.1.4c'
compile name: 'xstream-1.3.1'
runtimeOnly group: 'org.grails.plugins', name: 'jquery', version: '1.11.1'
runtimeOnly group: 'org.grails.plugins', name: 'resources', version: '1.2.14'
implementation group: 'org.grails.plugins', name: 'bubbling', version: '1.5.1'
implementation group: 'org.grails.plugins', name: 'calendar', version: '1.2.1'
implementation group: 'org.grails.plugins', name: 'code-coverage', version: '1.1.6'
implementation group: 'org.grails.plugins', name: 'webflow', version: '2.1.0'
compile "org.grails.plugins:shiro:1.2.1"
implementation group: 'org.grails.plugins', name: 'yui', version: '2.8.2.1'
implementation group: 'org.apache.tomcat', name: 'tomcat', version: '7.0.70', ext: 'pom'
compile "org.grails.plugins:calendar:1.2.1"
implementation group: 'org.grails.plugins', name: 'ckeditor', version: '4.5.9.0'
implementation group: 'org.apache.commons', name: 'commons-io', version: '1.3.2'
provided "opensymphony:quartz-all:1.6.3"
runtime "commons-io:commons-io:2.4"
runtime "org.springframework:spring-context-support:3.1.0.RELEASE"
runtime "org.springframework:spring-jms:3.1.0.RELEASE"
runtime "org.jboss.logging:jboss-logging:3.2.1.Final"
runtime "commons-dbcp:commons-dbcp:1.4"
compile 'org.springframework:spring-jms:5.1.20.RELEASE'
}
bootRun {
ignoreExitValue true
jvmArgs(
'-Dspring.output.ansi.enabled=always',
'-noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
grails{
pathingJar = true
}
P.S. -> getting similar errors for other dependencies too -> too a "grails dependency-report" and got this. Dont know how to resolve it.(Below is just a path. Thw hole report is too long)
+--- myproject-common (n) //A required jar from my another project
+--- commons-collections4-4.1 (n)
+--- commons-discovery-0.2 (n)
+--- commons-logging-1.0.4 (n)
+--- concurrent (n)
+--- CSVUpload (n)
+--- DynamicJasper-3.0.4 (n)
+--- hibernate-entitymanager (n)
+--- hibernate-search (n)
+--- hibernate-validator (n)
+--- myproject-intf-integration (n) //A required jar from my another project
+--- iText-2.1.4 (n)
+--- jasperreports-3.1.4 (n)
+--- jaxb1-impl (n)
+--- jaxb-api (n)
+--- jaxb-impl (n)
+--- jaxb-xjc (n)
+--- jaxrpc (n)
+--- jbossall-ideas-client (n)
+--- jboss-aop-jdk50 (n)
+--- jboss-jaxws (n)
+--- jboss-messaging-client (n)
+--- jboss-remoting (n)
+--- jboss-saaj (n)
+--- jboss-serialization (n)
+--- jbossws-client (n)
+--- jbossws-common (n)
+--- jbossws-spi (n)
+--- jboss-xml-binding (n)
+--- jms (n)
+--- jnp-client (n)
+--- jsr173_1.0_api (n)
+--- lucene-core (n)
+--- mail (n)
+--- mysql-connector-java-5.1.20 (n)
+--- policy (n)
+--- saaj (n)
+--- sfdcws (n)
+--- sqljdbc4-1 (n)
+--- trove (n)
+--- wsdl4j-1.5.1 (n)
+--- xercesImpl (n)
+--- xmlbeans-3.1.0 (n)
+--- xpp3_min-1.1.4c (n)
+--- xstream-1.3.1 (n)
+--- org.grails.plugins:quartz:2.0.13 (n)
+--- commons-io:commons-io:2.8.0 (n)
+--- org.springframework:spring-context-support:3.2.18.RELEASE (n)
+--- org.apache.poi:poi-ooxml-schemas:4.1.2 (n)
+--- org.apache.poi:poi:4.1.2 (n)
+--- org.apache.poi:poi-ooxml:4.1.2 (n)
+--- org.quartz-scheduler:quartz:1.7.2 (n)
\--- org.grails.plugins:jms:2.0.0.RC2 (n)
I have also tried deleting .m2, .grails, .gradle, grails clean and basically everything related to resetting the project
From the error, it looks like your application is not able to find org.apache.poi.ss.usermodel.Workbook. It may be due to multiple reasons, such as:
The Apache poi JAR is not present in the classpath. So, you would need to add the corresponding dependencies.
It may also happen when you have different version of multiple poi libraries, which I think are not compatible with each other. In this case, you need to make sure that every poi dependency is pointing to the same version.
Lastly, you may want to check that the class with same package is present in the respective version of library. The easiest way to check if you are using JetBrains IntelliJ Idea is to navigate to class.
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 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.