When I run Junit tests from Eclipse it all passes, however when I run the test from a gradle task which is literally just a test task it fails with the following error message:
java.lang.IllegalStateException at PluginLoader.java:88
Caused by: java.lang.IllegalStateException at DefaultMockitoPlugins.java:85
Caused by: java.lang.reflect.InvocationTargetException at NativeConstructorAccessorImpl.java:-2
Caused by: org.mockito.exceptions.base.MockitoInitializationException at Reporter.java:1131
Caused by: java.lang.NoClassDefFoundError at SubclassInjectionLoader.java:34
Caused by: java.lang.ClassNotFoundException at BuiltinClassLoader.java:581
Here are my gradle plugins and dependencies:
plugins {
id 'java-library'
id 'project-report'
id 'org.springframework.boot' version '2.6.8'
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven-publish'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', {
exclude module: "spring-boot-starter-jetty"
}
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
implementation group: 'org.springframework', name: 'spring-oxm', version: '5.3.20'
implementation group: 'org.eclipse.persistence', name: 'org.eclipse.persistence.moxy', version: '2.7.9'
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.9'
implementation group: 'org.liquibase', name: 'liquibase-core', version: '4.8.0'
implementation group: 'javax.cache', name: 'cache-api'
implementation group: 'org.ehcache', name: 'ehcache'
implementation group: 'org.apache.commons', name: 'commons-text', version: '1.9'
implementation group: 'net.iharder', name: 'base64', version: '2.3.9'
implementation group: 'org.freemarker', name: 'freemarker', version: '2.3.31'
//implementation group: 'com.nimbusds', name: 'nimbus-jose-jwt', version: '9.15.2'
//implementation group: 'org.apache.cxf', name: 'cxf-rt-rs-security-jose', version: '3.4.5'
implementation group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.15'
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13', {
exclude module: "commons-codec:commons-codec"
}
implementation group: 'org.apache.poi', name: 'poi-ooxml', version: '5.2.2', {
exclude module: "commons-codec:commons-codec"
}
implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
implementation group: 'commons-cli', name: 'commons-cli', version: '1.5.0'
implementation group: 'xerces', name: 'xercesImpl', version: '2.12.2'
testImplementation group: 'com.h2database', name: 'h2'
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', {
exclude group: "org.junit.jupiter"
}
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.6.1'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.23.0'
testRuntimeOnly group: 'org.junit.platform', name: 'junit-platform-commons', version: '1.8.2'
testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine', {
exclude module: "org.hamcrest:hamcrest-core"
}
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.22'
testImplementation group: 'org.projectlombok', name: 'lombok', version: '1.18.22'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
}
If I delete testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.6.1' it runs successfully, so it seems like somehow that dependency causes the issue, but unfortunately I definitely need that.
I have both JUnit 4 and JUnit 5 tests in my project. There are some test with #RunWith(SpringRunner.class) and some with #ExtendWith(MockitoExtension.class) annotations. I am using Java 11.
Any ideas are welcomed!
You probably use this plugin.
apply plugin: 'io.spring.dependency-management'
and this plugin fix the bytebuddy version to 1.11.22 where mockito 4.6.1 need 1.12.10.
So according to Could not initialize plugin: interface org.mockito.plugins.MockMaker after upgrading Mockito from 4.4.0 to 4.5.0
You need to add
testImplementation 'net.bytebuddy:byte-buddy:1.12.10'
To override the version.
Related
I migrate my app from Spring Boot 1.5.22 to 2.7.0 and I have a problem. Java 8. To migrate to 2.0.0 I have to replace save () with saveAll (), replace the postgres driver: compile group: 'postgresql', name: 'postgresql', version: '9.1-901-1.jdbc4' with implementation ' org.postgresql: postgresql: 42.2.9 ', I also add this line to application.properties:
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation = true. After that, I build without mistakes, but precisely: when I start shooting with Postman, with the correct token I get 401. (Before it was 200). When I started analyzing it, it turned out that after Spring migration, when the project is being built, postgres tables on localhost are created correctly, but they are empty, (that's why I get 401). I don't know how to work around it. Would you have an idea? I'm pasting build.gradle:
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.0.RELEASE'
}
}
plugins {
id "io.franzbecker.gradle-lombok" version "1.11"
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: "io.spring.dependency-management"
project.version = '1.1.5'
jar {
baseName = 'refurbishment'
version = project.version
}
sourceSets {
util {
compileClasspath += sourceSets.main.runtimeClasspath
}
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
maven { url "http://projectlombok.org/mavenrepo" }
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: '2.5.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version:'1.5.8.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-jwt', version:'1.1.1.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.5.8.RELEASE'
implementation 'org.springframework.boot:spring-boot-properties-migrator:2.1.18.RELEASE'
testCompile 'org.springframework.boot:spring-boot-starter-test'
compile group: 'org.hibernate', name: 'hibernate-validator', version:'5.2.4.Final'
compile group: 'com.google.guava', name: 'guava', version:'16.0.1'
compile group: 'joda-time', name: 'joda-time', version:'2.8.2'
compile group: 'commons-lang', name: 'commons-lang', version:'2.6'
compile group: 'net.sf.ehcache', name: 'ehcache-core', version:'2.6.9'
implementation 'org.postgresql:postgresql:42.2.9'
compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.6.0'
compile group: 'org.projectlombok', name: 'lombok', version:'1.16.6'
compile group: 'org.apache.commons', name: 'commons-csv', version:'1.2'
compile group: 'com.google.code.gson', name: 'gson', version:'2.6.2'
compile group: 'commons-io', name: 'commons-io', version:'2.4'
compile group: 'org.json', name: 'json', version:'20160212'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version:'2.5.0'
compile group: 'io.springfox', name: 'springfox-swagger2', version:'2.5.0'
compile group: 'com.fasterxml', name: 'classmate', version:'1.3.1'
compile 'com.microsoft.azure:azure-storage:5.4.0'
runtime group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '6.3.4.jre8-preview'
compile files('libs/PDFjet-5.1.jar')
testCompile(group: 'junit', name: 'junit')
//DBUnit
testCompile 'org.dbunit:dbunit:2.5.3'
testCompile 'com.github.springtestdbunit:spring-test-dbunit:1.3.0'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version:'1.3'
testCompile group: 'org.assertj', name: 'assertj-core', version:'1.7.0'
testCompile(group: 'org.mockito', name: 'mockito-core', version:'1.10.19') {
exclude(module: 'hamcrest-core')
}
testCompile group: 'org.springframework', name: 'spring-test', version:'4.2.6.RELEASE'
testCompile group: 'com.jayway.jsonpath', name: 'json-path', version:'2.0.0'
testCompile group: 'com.jayway.jsonpath', name: 'json-path-assert', version:'0.9.1'
}
bootRun {
def profiles = findProperty('profiles')
if (profiles) {
args = ["--spring.profiles.active=" + profiles]
}
}
task copyWebConfig(type: Copy) {
from('src/main/templates') {
include 'web.config'
}
into "$buildDir/libs"
filter(ReplaceTokens, tokens: [VERSION: project.version])
inputs.property("VERSION", project.version)
}
assemble.dependsOn(copyWebConfig)
Solved :) Added spring.datasource.initialization-mode=always to application.properties (working for Spring Boot 2.0.0)
I am using QueryDSL with Lombok and gradle. Q classes are getting generated, also IDEA can see them and there is no compiler error but when i try to execute gradle build i get :
error: cannot find symbol
import QRole;
So files are generated but gradle build like can't see them. All of solutions i found are not working and what ever i do i still get this error. Here is my gradle.build :
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'checkstyle'
id 'org.sonarqube' version '3.3'
id 'jacoco'
id 'idea'
id 'com.github.ben-manes.versions' version '0.42.0'
}
dependencies {
// Annotation processors
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
// Mapstruct
implementation group: 'org.mapstruct', name: 'mapstruct', version: mapstructVersion
annotationProcessor group: 'org.mapstruct', name: 'mapstruct-processor', version: mapstructVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
annotationProcessor group: 'javax.annotation', name: 'javax.annotation-api', version: javaxAnnotationVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
annotationProcessor group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.2-api', version: jpaVersion
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
implementation group: 'com.querydsl', name: 'querydsl-apt', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-jpa', version: querydslVersion
implementation group: 'com.querydsl', name: 'querydsl-sql', version: querydslVersion
// Spring boot
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.retry', name: 'spring-retry', version: springRetry
// Promotheus Monitoring (exposes /actuator/promotheus)
runtimeOnly 'io.micrometer:micrometer-registry-prometheus'
// Persistence
runtimeOnly group: 'org.postgresql', name: 'postgresql', version: postgresVersion
implementation group: 'org.flywaydb', name: 'flyway-core', version: flywayVersion
implementation group: 'org.hibernate', name: 'hibernate-jcache', version: hibernateVersion
implementation(group: 'org.hibernate', name: 'hibernate-spatial', version: hibernateVersion) {
exclude group: 'org.postgresql', module: 'postgresql'
}
implementation group: 'com.vladmihalcea', name: 'hibernate-types-52', version: hibernateTypesVersion
// Apache commons
implementation group: 'org.apache.commons', name: 'commons-lang3', version: apacheCommonsLangVersion
implementation group: 'org.apache.commons', name: 'commons-collections4', version: apacheCommonsCollectionVersion
// Swagger
implementation group: 'io.springfox', name: 'springfox-swagger2', version: swaggerVersion
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: swaggerVersion
// Jackson Datatype Jts
implementation group: 'com.bedatadriven', name: 'jackson-datatype-jts', version: jacksonDatatypeJTSVersion
// JWT
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: jjwtVersion
// Logging dependencies
runtimeOnly group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: logstashVersion
// Tests
testImplementation(group: 'org.springframework.boot', name: 'spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
// Mockito
testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
testImplementation group: 'org.mockito', name: 'mockito-inline', version: mockitoVersion
//JUnit
testImplementation group: 'junit', name: 'junit', version: junitVersion
//CSV
implementation group: 'org.apache.commons', name: 'commons-csv', version: apacheCommonsCsvVersion
// S3
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: awsSdkVersion
// SES
implementation group: 'com.amazonaws', name: 'aws-java-sdk-ses', version: awsSdkVersion
// AWS Secrets Manager
implementation group: 'com.amazonaws', name: 'aws-java-sdk-secretsmanager', version: awsSdkVersion
// RDS IAM access control
implementation group: 'io.magj', name: 'iam-jdbc-driver', version: '0.1.8'
// Scheduling
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-spring', version: shedLockVersion
implementation group: 'net.javacrumbs.shedlock', name: 'shedlock-provider-jdbc-template', version: shedLockVersion
}
dependencies {
compileOnly "com.querydsl:querydsl-jpa:${querydslVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor(
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:${hibernateJPAVersion}",
"javax.annotation:javax.annotation-api:${javaxAnnotationVersion}",
"org.projectlombok:lombok"
)
}
Working with Gradle, QueryDSL and Lombok together is a tricky job, but luckily there are few plugins which makes it easy. Here is the code that works.
plugins {
id 'org.springframework.boot' version '2.6.4'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'idea'
id 'io.franzbecker.gradle-lombok' version '5.0.0'
id 'com.ewerk.gradle.plugins.querydsl' version '1.0.10'
}
querydsl {
library = 'com.querydsl:querydsl-apt:5.0.0'
jpa = true
}
configurations {
querydsl.extendsFrom implementation, compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
project.afterEvaluate {
project.tasks.compileQuerydsl.options.compilerArgs = [
"-proc:only",
"-processor", project.querydsl.processors() +
',lombok.launch.AnnotationProcessorHider$AnnotationProcessor'
]
}
sourceSets {
main {
java {
srcDirs = ['src/main/java', 'src/querydsl/java']
}
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.querydsl:querydsl-jpa:5.0.0'
}
io.franzbecker.gradle-lombok and com.ewerk.gradle.plugins.querydsl are the required plugins to work all 3 correctly.
I received the following error
java.lang.NoClassDefFoundError: org/junit/platform/commons/util/ClassNamePatternFilterUtils
at org.junit.platform.launcher.core.LauncherFactory.loadAndFilterTestExecutionListeners(LauncherFactory.java:122)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:108)
at org.junit.platform.launcher.core.LauncherFactory.create(LauncherFactory.java:75)
at org.eclipse.jdt.internal.junit5.runner.JUnit5TestLoader.(JUnit5TestLoader.java:34)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:350)
at java.base/java.lang.Class.newInstance(Class.java:645)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createRawTestLoader(RemoteTestRunner.java:371)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.createLoader(RemoteTestRunner.java:366)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.defaultInit(RemoteTestRunner.java:310)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.init(RemoteTestRunner.java:225)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.commons.util.ClassNamePatternFilterUtils
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 16 more
and this my gradle file
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-validation'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-json'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
runtime 'org.springframework.boot:spring-boot-starter-tomcat'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testCompile('org.apache.commons:commons-compress:1.19')
testImplementation 'io.projectreactor:reactor-test'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'commons-codec', name: 'commons-codec', version: '1.14'
compile group: 'org.json', name: 'json', version: '20180813'
compile group: 'com.opencsv', name: 'opencsv', version: '5.1'
// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '28.1-jre'
// https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.852'
compile("io.springfox:springfox-swagger2:2.9.2"){
exclude group:"com.google.guava", module:"guava"
}
compile("io.springfox:springfox-swagger-ui:2.9.2"){
exclude group:"com.google.guava", module:"guava"
}
runtime group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: 'Hoxton.SR6', ext: 'pom'
compile group: 'io.spring.gradle', name: 'dependency-management-plugin', version: '1.0.9.RELEASE'
implementation ('org.reflections:reflections:0.9.10') {
exclude group: 'com.google.code.findbugs', module: 'annotations'
}
implementation 'commons-io:commons-io:2.5'
implementation("org.springframework.cloud:spring-cloud-starter-openfeign:2.2.0.RELEASE"){
exclude group:"ch.qos.logback", module:"logback-classic"
}
implementation 'io.github.openfeign:feign-jackson:11.0'
implementation 'io.github.openfeign:feign-httpclient:11.0'
compile group: 'io.github.openfeign.form', name: 'feign-form-spring', version: '3.5.0'
compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.11.0'
implementation 'org.alfresco:alfresco-data-model:6.19#jar'
implementation 'xerces:xercesImpl:2.9.1#jar'
}
test {
useJUnitPlatform()
}
I found missing the following lines in build.gradle file
testRuntimeOnly 'org.junit.platform:junit-platform-commons:1.7.1'
after adding this it works completely fine.
I have a rather strange issue with my Spring boot application which has been driving me around the bend.
So I have my Spring boot API which is in Github and uses Gradle to manage my dependencies. If I add a dependency and compile the project everything works fine. However, if I decide I do not need said dependency anymore and remove it from my build file, my Project will no longer compile stating it cant find packages / symbols for dependencies unrelated to what I removed.
Has anyone seen something like this before? As an FYI I'm using Intellij.
To give an example, here is my current build file:
plugins {
id "org.springframework.boot" version "2.4.2"
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id "com.commercehub.gradle.plugin.avro" version "0.21.0"
id "idea"
}
group 'org.example'
version '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
ext {
avroVersion = "1.10.1"
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://packages.confluent.io/maven/"
}
}
avro {
createSetters = true
fieldVisibility = "PRIVATE"
}
apply plugin: "war"
dependencies {
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.6'
compile group: 'co.elastic.logging', name: 'logback-ecs-encoder', version: '0.5.2'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.860'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache', version: '2.4.3'
// compile 'redis.clients:jedis:3.5.1'
implementation group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.3.3.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '4.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.3.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.4.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.4.2'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.6.5'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server', version: '2.4.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.2'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
compile group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.passay', name: 'passay', version: '1.6.0'
compile group: 'com.google.guava', name: 'guava', version: '30.0-jre'
// https://mvnrepository.com/artifact/com.auth0/java-jwt
compile group: 'com.auth0', name: 'java-jwt', version: '3.12.0'
compile group: 'io.confluent', name: 'kafka-schema-registry-client', version: '6.0.0'
compile group: 'io.confluent', name: 'kafka-avro-serializer', version: '6.0.0'
compile group: 'io.confluent', name: 'monitoring-interceptors', version: '6.0.0'
compile(group: 'io.confluent', name: 'kafka-streams-avro-serde', version: '6.0.0') {
exclude(module: 'log4j-over-slf4j')
}
compile "org.apache.avro:avro:1.10.1"
implementation "org.apache.avro:avro:${avroVersion}"
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-web'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
jar {
manifest {
attributes(
'Main-Class': 'com.test.TestApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
test {
useJUnitPlatform()
}
Now let's assume I don't want logstash so I remove it, this happens with any dependency
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.6'
Now my build file looks like this:
plugins {
id "org.springframework.boot" version "2.4.2"
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
id "com.commercehub.gradle.plugin.avro" version "0.21.0"
id "idea"
}
group 'org.example'
version '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
ext {
avroVersion = "1.10.1"
}
repositories {
mavenCentral()
jcenter()
maven {
url "https://packages.confluent.io/maven/"
}
}
avro {
createSetters = true
fieldVisibility = "PRIVATE"
}
apply plugin: "war"
dependencies {
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
// REMOVED implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '6.6'
compile group: 'co.elastic.logging', name: 'logback-ecs-encoder', version: '0.5.2'
compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.860'
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-cache', version: '2.4.3'
// compile 'redis.clients:jedis:3.5.1'
implementation group: 'com.mashape.unirest', name: 'unirest-java', version: '1.4.9'
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
compile('org.springframework.boot:spring-boot-starter-data-elasticsearch')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb', version: '2.3.3.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '4.0.4.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.3.RELEASE'
compile group: 'org.springframework.security', name: 'spring-security-oauth2-client', version: '5.4.0'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.4.2'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.6.5'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server', version: '2.4.2'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
compile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.2'
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
compile group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
compile group: 'org.passay', name: 'passay', version: '1.6.0'
compile group: 'com.google.guava', name: 'guava', version: '30.0-jre'
// https://mvnrepository.com/artifact/com.auth0/java-jwt
compile group: 'com.auth0', name: 'java-jwt', version: '3.12.0'
compile group: 'io.confluent', name: 'kafka-schema-registry-client', version: '6.0.0'
compile group: 'io.confluent', name: 'kafka-avro-serializer', version: '6.0.0'
compile group: 'io.confluent', name: 'monitoring-interceptors', version: '6.0.0'
compile(group: 'io.confluent', name: 'kafka-streams-avro-serde', version: '6.0.0') {
exclude(module: 'log4j-over-slf4j')
}
compile "org.apache.avro:avro:1.10.1"
implementation "org.apache.avro:avro:${avroVersion}"
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-web'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
jar {
manifest {
attributes(
'Main-Class': 'com.test.TestApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
test {
useJUnitPlatform()
}
Once I hit build I'll get non related logstash compilation errors such as in various classes:
java: package lombok does not exist
java: package org.openapitools.jackson.nullable does not exist
java: cannot find symbol
symbol: class Getter
java: package org.springframework.data.domain does not exist
java: package org.openapitools.jackson.nullable does not exist
I've tried reimporting my project, I've deleted it and pull down a fresh copy from Git..I'm at a loss now. Please if anyone has come across this let me know as google is failing me now :-/
Many thanks
EDIT: Please note for clarification, this seems to only happen when I have Intellij performing the build and Run.
If I switch the below to Gradle I've no issues remove dependencies as described above. However, I'd like to keep Intellij performing the build and run.
Edit:
Adding gradle-wrapper.properties in case it helps
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Also, following a suggestion below, I purged the cache in Intellij which Did solve the problem, However, once I remove another dependency I'm back to getting the errors above.
Second Edit
I'm not sure it matters but I noticed since Lombok is the main error I checked the annotation settings.
Why is there a default & a gradle imported, Would that be causing any of the issues?
I'm using the Xerces jar in a gradle project, I use then the jar of this project inside a gradle plugin: In fact, I'm developing a gradle plugin with custom tasks that use some functions of the gradle project jar; when I try to run the tasks, I have this error; however when I try to run the function from the gradle project it works correctly. When I tried to search on the net, I found that the cause of the error is that the JRE packages a version of Xerces but I don't know how to resolve the problem...
dependencies block of my gradle project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
dependencies {
testImplementation 'junit:junit:4.12'
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
implementation (group: 'commons-logging', name: 'commons-logging', version: '1.2')
implementation(group: 'log4j', name: 'log4j', version: '1.2.17')
implementation (group: 'javax', name: 'javaee-api', version: '8.0')
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final'
implementation (group: 'commons-io', name: 'commons-io', version: '2.6')
implementation(group: 'org.apache.ant', name: 'ant', version: '1.10.3')
implementation( group: 'xerces', name: 'xercesImpl', version: '2.11.0')
implementation (group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3')
implementation( group: 'net.sf.jt400', name: 'jt400', version: '9.5')
implementation(group: 'mysql', name: 'mysql-connector-java', version: '5.0.4')
implementation (group: 'org.apache.derby', name: 'derbyclient', version: '10.14.2.0')
implementation group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.3'
implementation group: 'Ext', name: 'sqljdbc', version: 'sqljdbc'
implementation group: 'toplink.essentials', name: 'toplink-essentials', version: '2.1-60',transitive:false
implementation group: 'org.springframework', name: 'spring', version: '2.5.6'
implementation group: 'org.swinglabs', name: 'swing-layout', version: '1.0.3'
implementation group: 'xalan', name: 'xalan', version: '2.7.2'
implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.6.6'
implementation group: 'org.gradle', name: 'gradle-tooling-api', version: '4.3'
implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
implementation group: 'org.hibernate', name: 'hibernate-cglib-repack', version: '2.1_3'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'xml-apis', name: 'xml-apis', version: '1.4.01'
implementation (group: 'xalan', name: 'serializer', version: '2.7.2')
implementation(group:'org.apache.ant', name: 'ant-launcher', version: '1.10.3')
}
Here is the Build.gradle of my gradle plugin:
group = 'CustomPlugin'
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'
archivesBaseName ='CustomPluginGradle'
version='10.0.0'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'repo-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
defaults {
publishConfigs('archives', 'published')
publishBuildInfo = false
publishArtifacts = false
publishPom = true
publishIvy = false
}
}
resolve {
repository {
repoKey = 'repo-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
CustomPluginGradle(MavenPublication) {
group='CustomPlugin'
}
}
}
jar {
from ('src/main/java'){
exclude '**/**.java'}
}
repositories {
jcenter()
}
dependencies {
compile gradleApi()
testImplementation 'junit:junit:4.12'
testImplementation group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
implementation (group: 'commons-logging', name: 'commons-logging', version: '1.2')
implementation(group: 'log4j', name: 'log4j', version: '1.2.17')
implementation (group: 'javax', name: 'javaee-api', version: '8.0')
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final'
implementation (group: 'commons-io', name: 'commons-io', version: '2.6')
implementation(group: 'org.apache.ant', name: 'ant', version: '1.10.3')
implementation( group: 'xerces', name: 'xercesImpl', version: '2.11.0')
implementation (group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.3')
implementation( group: 'net.sf.jt400', name: 'jt400', version: '9.5')
implementation(group: 'mysql', name: 'mysql-connector-java', version: '5.0.4')
implementation (group: 'org.apache.derby', name: 'derbyclient', version: '10.14.2.0')
implementation group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.3'
implementation group: 'Ext', name: 'sqljdbc', version: 'sqljdbc'
implementation group: 'toplink.essentials', name: 'toplink-essentials', version: '2.1-60',transitive:false
implementation group: 'org.springframework', name: 'spring', version: '2.5.6'
implementation group: 'org.swinglabs', name: 'swing-layout', version: '1.0.3'
implementation group: 'xalan', name: 'xalan', version: '2.7.2'
implementation group: 'com.github.javaparser', name: 'javaparser-core', version: '3.6.6'
implementation group: 'org.gradle', name: 'gradle-tooling-api', version: '4.3'
implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
implementation group: 'org.hibernate', name: 'hibernate-cglib-repack', version: '2.1_3'
implementation group: 'xml-apis', name: 'xml-apis', version: '1.4.01'
implementation (group: 'xalan', name: 'serializer', version: '2.7.2')
implementation(group:'org.apache.ant', name: 'ant-launcher', version: '1.10.3')
}
configurations.all {
transitive = false
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
It a conflict between your version of Xerces 2.11.0 and a version brought through a transitive dependency. Try this :
configurations.all {
resolutionStrategy {
force 'xerces:xercesImpl:2.11.0'
}
}