Cannot resolve class TableOptions generated by jOOQ - gradle

I'm using jOOQ 3.13.0 with Gradle.
Here are some related excerpts from the build.gradle
...
buildscript {
dependencies {
classpath 'org.jooq:jooq-codegen:3.13.3'
classpath 'org.postgresql:postgresql:42.2.5'
}
}
...
dependencies {
compile 'org.jooq:jooq:3.13.3'
}
...
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd') {
jdbc() {
driver('org.postgresql.Driver')
url('jdbc:postgresql://localhost:5432/metrics')
user('postgres')
password('pwd')
}
generator() {
database() {
inputSchema('public')
}
// Watch out for this caveat when using MarkupBuilder with "reserved names"
// - https://github.com/jOOQ/jOOQ/issues/4797
// - http://stackoverflow.com/a/11389034/521799
// - https://groups.google.com/forum/#!topic/jooq-user/wi4S9rRxk4A
generate() {
}
target() {
packageName('metrics.jooq')
directory('src/main/java')
}
}
}
After I run gradle clean build it generates the code successfully but it cannot be compiled because it contains:
import org.jooq.TableOptions;
which cannot be resolved. How can I resolve this. It's very strange that it generates code that cannot be compiled...
I noticed that Gradle has downloaded version 3.11.9 instead of 3.13.3 for some reason.
After that I changed all the jooq related versions to 3.11.9 (also xsd version) in build.gradle and ran the build but got:
Error while reading XML configuration
Here is the end of the stack trace:
...
Caused by: org.jooq.codegen.GeneratorException: Error while reading XML configuration
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:931)
at org.jooq.codegen.GenerationTool.generate(GenerationTool.java:218)
at org.jooq.codegen.GenerationTool$generate.call(Unknown Source)
at build_abyn1owj8gv09akc1mcgpsxr1.run(/media/wd/job/otr/mk/ufos-portal-incubate/solutions/mk-dashboard/build.gradle:56)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:90)
... 104 more
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at org.jooq.codegen.GenerationTool.load(GenerationTool.java:914)
... 108 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
... 109 more
I tried to resolve it as suggested here
https://github.com/jOOQ/jOOQ/issues/9066
and added to build.gradle
dependencies {
classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '3.0.0-M4'
classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '3.0.0-M4'
classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
...
but without success

I've solved the problem by using the right dependencies
Here is the excerpt from build.gradle
buildscript {
dependencies {
classpath group: 'com.sun.activation', name: 'javax.activation', version: '1.2.0'
classpath group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0.1'
classpath group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '2.3.1'
classpath 'org.jooq:jooq-codegen:3.11.9'
classpath 'org.postgresql:postgresql:42.2.5'
...

Related

Gradle 5.5 Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor

With Gradle 5.5 and com.github.maiflai:gradle-scalatest:0.24 I am getting below exception
at com.github.maiflai.ScalaTestAction.makeAction(ScalaTestAction.groovy:68)
at com.github.maiflai.ScalaTestAction$makeAction.callStatic(Unknown Source)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy:32)
at com.github.maiflai.ScalaTestAction.execute(ScalaTestAction.groovy)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:702)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:669)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$5.run(ExecuteActionsTaskExecuter.java:401)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:402)
build.gradle:
repositories {
maven {
url "$artifactory_base_url/public-maven-virtual"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven {
url "$artifactory_base_url/eg-maven-release-local"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath "org.scoverage:gradle-scoverage:2.5.0"
classpath "com.github.maiflai:gradle-scalatest:0.24"
classpath "com.amazonaws:aws-java-sdk:1.11.399"
classpath "com.github.jengelman.gradle.plugins:shadow:4.0.4"
}
}
....
....
dependencies {
// scala
compileOnly("org.scala-lang:scala-library:2.12.15")
compileOnly("org.scala-lang:scala-reflect:2.12.15")
compile("org.scala-lang:scala-compiler:2.12.15")
// Spark
compileOnly("org.apache.spark:spark-core_2.12:${rev_spark}"){
exclude group: 'log4j'
}
compileOnly("org.apache.spark:spark-sql_2.12:${rev_spark}"){
exclude group: 'log4j'
}
compile("io.delta:delta-core_2.12:1.0.1")
compile("org.apache.spark:spark-sql-kafka-0-10_2.12:3.1.2")
// Config
compile "com.typesafe:config:1.3.2"
// Unit Testing
testCompile("junit:junit:${rev_junit}")
testCompile("org.mockito:mockito-core:2.20.0")
testCompile("org.scalatest:scalatest_2.12:3.2.11")
testCompile("org.scalamock:scalamock_2.12:4.3.0")
testCompile("org.scalatestplus:mockito-3-4_2.12:3.2.10.0")
testRuntime("com.vladsch.flexmark:flexmark-all:0.34.0")
// Scala test coverage
scoverage "org.scoverage:scalac-scoverage-plugin_2.12.15:2.0.0-M5"
scoverage "org.scoverage:scalac-scoverage-runtime_2.12:2.0.0-M5"
compile("com.expedia.ers.sdp:sdp-velocity-common:1.4.0") {
transitive = false
}
// AWS Dependencies
compile("com.amazonaws:aws-java-sdk-s3:1.11.399")
compile("com.amazonaws:aws-java-sdk-secretsmanager:1.11.399")
// Log4j dependencies
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.17.1'
// ES Dependencies
compile("org.elasticsearch:elasticsearch-spark-20_2.12:8.1.0")
}
I tried to change the version of the com.github.maiflai:gradle-scalatest:0.25 but it start throwing below exception
An exception or error caused a run to abort. This may have been caused by a problematic custom reporter.
java.lang.NoClassDefFoundError: com.vladsch.flexmark.util.ast.Node
at org.scalatest.tools.ReporterFactory.createHtmlReporter(ReporterFactory.scala:194)
at org.scalatest.tools.ReporterFactory.getReporterFromConfiguration(ReporterFactory.scala:245)
at org.scalatest.tools.ReporterFactory.$anonfun$createReportersFromConfigurations$1(ReporterFactory.scala:254)
at org.scalatest.tools.ReporterFactory$$Lambda$63/0x0000000000000000.apply(Unknown Source)
at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:286)
at scala.collection.TraversableLike$$Lambda$9/0x0000000000000000.apply(Unknown Source)
at scala.collection.Iterator.foreach(Iterator.scala:943)
at scala.collection.Iterator.foreach$(Iterator.scala:943)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1431)
at scala.collection.IterableLike.foreach(IterableLike.scala:74)
at scala.collection.IterableLike.foreach$(IterableLike.scala:73)
at org.scalatest.tools.ReporterConfigurations.foreach(ReporterConfiguration.scala:42)
at scala.collection.TraversableLike.map(TraversableLike.scala:286)
at scala.collection.TraversableLike.map$(TraversableLike.scala:279)
at org.scalatest.tools.ReporterConfigurations.map(ReporterConfiguration.scala:42)
at org.scalatest.tools.ReporterFactory.createReportersFromConfigurations(ReporterFactory.scala:253)
at org.scalatest.tools.ReporterFactory.getDispatchReporter(ReporterFactory.scala:257)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:1480)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:971)
at org.scalatest.tools.Runner$.main(Runner.scala:775)
at org.scalatest.tools.Runner.main(Runner.scala)
Caused by: java.lang.ClassNotFoundException: com.vladsch.flexmark.util.ast.Node
at java.net.URLClassLoader.findClass(URLClassLoader.java:591)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:951)
at java.lang.ClassLoader.loadClass(ClassLoader.java:896)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:879)
... 21 more
FAILURE: Build failed with an exception.

org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor encountered while upgrading Groovy and Spock

Using Gradle 7.1.1, Java 16, Groovy 3.0.8 and Spock 2.0-groovy-3.0
I'm getting this error when running ./gradlew clean test
Caused by: java.util.ServiceConfigurationError: org.junit.platform.engine.TestEngine: org.spockframework.runtime.SpockEngine Unable to get public no-arg constructor
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:582)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:673)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNextService(ServiceLoader.java:1232)
at java.base/java.util.ServiceLoader$LazyClassPathLookupIterator.hasNext(ServiceLoader.java:1264)
at java.base/java.util.ServiceLoader$2.hasNext(ServiceLoader.java:1299)
at java.base/java.util.ServiceLoader$3.hasNext(ServiceLoader.java:1383)
at java.base/java.lang.Iterable.forEach(Iterable.java:74)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:95)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:97)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
... 25 more
Caused by: java.lang.NoClassDefFoundError: org/junit/platform/engine/support/discovery/SelectorResolver
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3305)
at java.base/java.lang.Class.getConstructor0(Class.java:3510)
at java.base/java.lang.Class.getConstructor(Class.java:2238)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:660)
at java.base/java.util.ServiceLoader$1.run(ServiceLoader.java:657)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:554)
at java.base/java.util.ServiceLoader.getConstructor(ServiceLoader.java:668)
... 36 more
Caused by: java.lang.ClassNotFoundException: org.junit.platform.engine.support.discovery.SelectorResolver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 44 more
This is the build.gradle for the module where error is reported:
dependencies {
implementation 'io.rest-assured:rest-assured'
implementation 'org.yaml:snakeyaml'
implementation 'com.fasterxml.jackson.core:jackson-databind'
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation('org.spockframework:spock-core') {
transitive = false
}
}
Parent module build.gradle file:
ext {
jupiterVersion = '5.7.2'
}
jar.enabled = false
subprojects {
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'codenarc'
jar.enabled = true
codenarc {
toolVersion = '1.4'
reportFormat = 'html'
configFile = new File('../../tool/codenarc/groovy-ruleset.groovy')
}
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
bomProperties(['selenium.version' : '3.141.59',
'rest-assured.version': '4.1.1'])
}
}
dependencies {
dependency 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
dependency 'org.spockframework:spock-core:2.0-groovy-3.0'
dependency 'com.athaydes:spock-reports:2.0-groovy-3.0'
dependency 'com.codeborne:selenide:5.3.1'
dependency 'org.hamcrest:hamcrest:2.1'
dependencySet(group: 'org.junit.jupiter', version: jupiterVersion) {
entry 'junit-jupiter'
entry 'junit-jupiter-api'
}
dependencySet(group: 'org.slf4j', version: '1.7.28') {
entry 'jcl-over-slf4j'
entry 'jul-to-slf4j'
}
dependencySet(group: 'org.aspectj', version: '1.9.4') {
entry 'aspectjrt'
entry 'aspectjweaver'
}
dependency 'io.rest-assured:rest-assured:4.1.1'
dependency 'org.postgresql:postgresql:42.2.8'
dependency 'org.yaml:snakeyaml:1.25'
dependency 'org.apache.poi:poi-ooxml:4.1.1'
dependency 'com.opencsv:opencsv:4.0'
dependency 'org.junit.platform:junit-platform-launcher:1.4.0'
}
}
test {
useJUnitPlatform()
}
}
Any help would be appreciated.
PS. This was working with Java 11, Groovy 2.5 and Spock 1.3-groovy-2.5
Have you added useJUnitPlatform()?
https://github.com/spockframework/spock-example/blob/master/build.gradle#L34
test {
useJUnitPlatform()
}
It was a problem with the parent project's build.gradle file.
I recently upgraded the spring boot version to 2.5.1.
After updating this entry in the build.gradle file the error went away.
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:2.5.1") {
bomProperties(['selenium.version' : '3.141.59',
'rest-assured.version': '4.1.1'])
}
}

Gradle spring-boot error - java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication

Below is my build.gradle file. I am using java 11 and IntelliJ 2019.2.2. As I run the application, I get: Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
As such the error or problem appears to be the same as the one you get when you upgrade from gradle version 2.x to anything 3.4 onwards, but I should not be getting the error with any recent IntelliJ version. I have cleaned the repository, idea cache etc. The main class (com.itreatmd.emr.Application) has only one line - SpringApplication.run(Application.class, args) and that throws this exception.
Also, when I build the tar file from command line and then explode the tar file, I do not see my jar file packaged under the lib folder of the tar file. I am clearly missing something, presumably something obvious, but just cannot get the handle to it.
buildscript {
ext {
springBootVersion = '2.2.1.RELEASE'
}
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
}
}
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id 'application'
id 'idea'
}
mainClassName = 'com.itreatmd.emr.Application'
group = 'com.itreatmd.emr'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = 1.8
repositories {
mavenCentral()
}
jar {
baseName = 'emrServices'
version = '1.0-SNAPSHOT'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jersey'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile group: 'commons-codec', name: 'commons-codec', version: '1.5'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20180813'
compile "org.apache.httpcomponents:httpmime:4.2.3"
compile group: 'org.yaml', name: 'snakeyaml', version: '1.8'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.3.1'
compile group: 'org.springframework', name: 'spring-webmvc', version: '3.1.1.RELEASE'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
jar {
manifest {
attributes 'Main-Class': 'com.itreatmd.emr.Application',
'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
}
}
i am using spring boot 2.2.5 and gradle 5.1.2.
run gradle build -x test, it will tell you what error it is.
in my case, it told me that error: package org.jasig.cas.client.authentication does not exist, but this package exists in fact.
then i remembered that i added a dependency runtimeOnly 'org.apereo.cas:cas-server-support-validation:5.3.15.1'
after comment this dependency, my project can start success.

slf4j LoggerFactory class definition not found with Gradle

I'm trying to build and run a Spark webserver that uses slf4j logging in IntelliJ. It builds fine (also in IntelliJ) on the computer that was used to originally add logging, but not on my machine.
Here's the full build.gradle file (see project(':webserver') for the part that uses the logger:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.avast.gradle:docker-compose-gradle-plugin:0.3.27"
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
apply plugin: "java"
apply plugin: "idea"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "findbugs"
apply plugin: "application"
apply plugin: "com.avast.gradle.docker-compose"
checkstyle {
configFile = "../config/checkstyle/checkstyle.xml" as File
toolVersion = "6.0"
}
}
project(':webserver') {
mainClassName = "org.passport.webserver.WebServer"
dependencies {
compile project(':core')
compile "com.sparkjava:spark-core:2.6.0"
testCompile 'junit:junit:4.12'
compile group: 'org.json', name: 'json', version: '20090211'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':customsUI') {
mainClassName = "org.passport.customsui.CustomsUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':handlerUI') {
mainClassName = "org.passport.handlerui.HandlerUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
project(':core') {
mainClassName = "org.passport.core.PassPortChaincode"
dependencies {
compile 'io.grpc:grpc-all:0.13.2'
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.glassfish:javax.json:1.1.0-M1'
compile files('lib/shim-client-1.0.jar')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}
Here's the code that uses the logger:
package org.passport.webserver;
import org.passport.webserver.endpoints.ContainerClaimDao;
import org.passport.webserver.endpoints.PackageClaimDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.path;
import static spark.Spark.post;
/**
* The server matches requests (routs) and calls the appropriate endpoints.
*/
public final class Server {
private static Logger logger = LoggerFactory.getLogger(Server.class);
private static ContainerClaimDao containers = new ContainerClaimDao();
private static PackageClaimDao packages = new PackageClaimDao();
private Server() {
}
/**
* Starts the router.
* #param args run arguments
*/
public static void main(String[] args) {
path("/containers/:container-id", () -> {
before("/*", (q, a) -> logger.info("Received api call: " + q.url() + "."));
post("", (request, response) -> containers.add(request, response));
get("/container-claims", (request, response) -> containers.get(request, response));
get("/package-claims", (request, response) -> packages.get(request, response));
});
}
}
And here's the error I get:
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\Users\lover\repositories\passport\webserver\build\classes\main;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.passport.webserver.Server
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.passport.webserver.Server.<clinit>(Server.java:18)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more
I've looked at several questions on StackOverflow, but none seem to solve the problem:
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory - I'm building with gradle, don't think I should have to download/ put some jar in my classpath
ClassNotFoundException: org.slf4j.LoggerFactory - Same as above
NoClassDefFoundError: org/slf4j/Logger - Again jar stuff
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory - I'm not sure whether "fat jars" / ShadowJar apply, and not sure how to modify my build file to use them
NoClassDefFoundError: org/slf4j/LoggerFactory while creating a runnable *.jar with gradle - I've tried refreshing gradle several times, restarting IntelliJ, and even restarting my restarting my computer
Gradle Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory - See below
I've tried the following dependencies:
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
compile 'org.slf4j:slf4j-api:1.7.24' and compile 'org.slf4j:slf4j-simple:1.7.24'
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
None of this seems to make a difference. Any ideas?
If you're using Gradle add these 2 lines to your build.gradle dependencies to use Spark 2.6.0
compile "com.sparkjava:spark-core:2.6.0"
compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'
I ended up deleting my Gradle cache (.gradle folder) and re-downloading everything, which solved the problem.

SLF4J AND LOG4J binding exception in spring boot app with ignite dependency

Hi,
Below exception is thrown when I include ignite dependency with my spring boot app. Even though reason seems obvious that 2 jars are in deadlock here, can you suggest me how can I fix this. I am not adding any of these jars directly and these are included automatically with other dependencies.
build.gradle
buildscript {
repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE")
classpath 'mysql:mysql-connector-java:5.1.34'
}
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
jcenter()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
// In this section you declare the dependencies for your production and test code
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("mysql:mysql-connector-java:5.1.34")
// Ignite dependencies
compile group: 'org.apache.ignite', name: 'ignite-core', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-spring', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-indexing', version: '1.6.0'
compile group: 'org.apache.ignite', name: 'ignite-rest-http', version: '1.6.0'
testCompile 'junit:junit:4.12'
}
Exception:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.21/7238b064d1aba20da2ac03217d700d91e02460fa/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/gradle/2.13/caches/modules-2/files-2.1/ch.qos.logback/logback-classic/1.1.7/9865cf6994f9ff13fce0bf93f2054ef6c65bb462/logback-classic-1.1.7.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:72)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:45)
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.boot.App.<clinit>(App.java:42)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError.
You have to exclude conflicting dependencies, like below.
Refer official documentation for more info.
exclude group: 'org.slf4j', module: 'slf4j-log4j12'
Example from the official documentation:

Resources