Gradle Package does not exist - java

I am trying to build Gradle using ./gradlew build but during compilation getting following error package not found.In eclipse I am able to run refresh gradle but in command prompt facing the below issue :
> Task :compileJava FAILED
/Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:3: error: package io.restassured does not exist
import static io.restassured.RestAssured.given;
^
/Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:3: error: static import only from classes and interfaces
import static io.restassured.RestAssured.given;
^
/Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:21: error: package org.apache.commons.lang3 does not exist
import org.apache.commons.lang3.StringUtils;
^
/Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:34: error: package io.restassured.response does not exist
import io.restassured.response.ExtractableResponse;
^
/Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:35: error: package io.restassured.response does not exist
import io.restassured.response.Response;
^
/Users/Documents/em-cedm-integ-test/src/main/java/com/CedmTest.java:3: error: package org.junit.runner does not exist
import org.junit.runner.JUnitCore;
^
^
Build.gradle file I am using
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java'
allprojects {
repositories {
// You can declare any Maven/Ivy/file repository here.
maven {
url "http://repo.hortonworks.com/content/repositories/releases"
}
maven {
url "${artifactory_contextUrl}"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven {
url "${artifactory_contextUrl}/ip-fci-maven-virtual"
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
configurations.all {
transitive = false
}
}
version = '1.0'
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.ibm.cedm.CedmTest'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
defaultTasks 'downloadFile'
dependencies {
compile group: 'com.google.guava', name: 'guava', version: '12.0.1'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.7'
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '0.11.0.3'
compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.1.2.2.6.4.0-91'
compile group: 'org.apache.hbase', name: 'hbase-common', version: '1.1.2.2.6.4.0-91'
compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.1.2.2.6.4.0-91'
compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.3.2.6.4.0-91'
compile group: 'com.tdunning', name: 'json', version: '1.8'
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.10'
compile group: 'org.apache.oozie', name: 'oozie-client', version: '4.2.0'
compileOnly group: 'io.swagger', name: 'swagger-annotations', version: '1.5.12'
compileOnly group: 'javax', name: 'javaee-api', version: '7.0'
compile group: 'ip-fci-generic-local.fcco-core', name: 'fci-core-utils', version: 'master'
compile(group: 'ip-fci-generic-local.media', name: 'db2jcc4', version: '11.1.3')
testImplementation 'junit:junit:4.12'
testCompile group: 'commons-codec', name: 'commons-codec', version: '1.9'
testCompile group: 'com.tdunning', name: 'json', version: '1.8'
testCompile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
testCompile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.6'
testCompile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.10'
testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
testCompile group: 'commons-logging', name: 'commons-logging', version: '1.2'
testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
testCompile group: 'io.rest-assured', name: 'rest-assured-common', version: '3.0.2'
testCompile group: 'io.rest-assured', name: 'json-path', version: '3.0.2'
testCompile group: 'io.rest-assured', name: 'xml-path', version: '3.0.2'
testCompile group: 'net.javacrumbs.json-unit', name: 'json-unit', version: '1.5.2'
testCompile group: 'net.javacrumbs.json-unit', name: 'json-unit-core', version: '1.5.2'
testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.4'
testCompile group: 'org.codehaus.groovy', name: 'groovy-json', version: '2.4.4'
testCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.25'
}
/*
test {
filter {
//include specific method in any of the tests
includeTestsMatching "*createBasicIndividualParty"
}
}
*/
Can someone please tell me why it is so? and what changes I should I make it to work?

How dependency mapped
dependencies mapped with testCompile will be compiled with src/test/java classes
dependencies mapped with compile will be compiled with src/main/java classes
Issue with the gradle config
Few dependencies are mapped as testCompile but it could be referenced in production code src/main/java.
testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
Should be
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'

Related

Spring Boot migration from 1.5.22 to 2.0.0

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)

Spring Boot: Project won't compile after changing gradle dependencies

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?

java.lang.RuntimeException: Error scanning entry module-info.class from jar

I try to run project with gretty. It throws exception:
10:47:39 WARN Failed startup of context o.a.g.JettyWebAppContext#52045dbe{/,file:/C:/IdeaProjects/example-tab/build/inplaceWebapp/,STARTING}
java.lang.RuntimeException: Error scanning entry module-info.class from jar file:/C:/Users/user1/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.10.0/fec5797a55b786184a537abd39c3fa1449d752d6/log4j-api-2.10.0.jar
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:913) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:831) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:164) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:549) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) ~[jetty-util-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) ~[jetty-util-9.2.24.v20180105.jar:9.2.24.v20180105]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_171]
Caused by: java.lang.UnsupportedOperationException: null
at org.objectweb.asm.ClassVisitor.visitModule(ClassVisitor.java:129) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.readModule(ClassReader.java:667) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.accept(ClassReader.java:503) ~[asm-6.1.1.jar:na]
at org.objectweb.asm.ClassReader.accept(ClassReader.java:355) ~[asm-6.1.1.jar:na]
at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:974) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parseJarEntry(AnnotationParser.java:956) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
at org.eclipse.jetty.annotations.AnnotationParser.parseJar(AnnotationParser.java:909) ~[jetty-annotations-9.2.24.v20180105.jar:9.2.24.v20180105]
... 6 common frames omitted
gradle:
plugins {
id 'java'
id 'war'
id "org.gretty" version "2.2.0"
}
group 'ru.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
ext {
SPRING_VERSION = '5.1.0.RELEASE'
JUNIT_VERSION = '5.3.1'
JACKSON_VERSION = '2.9.7'
}
repositories {
mavenCentral()
jcenter()
maven {
url 'https://oss.sonatype.org/content/repositories/releases/'
}
}
gretty {
springBootVersion = '2.0.5.RELEASE'
contextPath = "/"
}
dependencies {
annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compileOnly group: 'com.google.appengine', name: 'appengine-endpoints-deps', version: '1.9.65'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'org.springframework', name: 'spring-webmvc', version: SPRING_VERSION
compile group: 'org.springframework', name: 'spring-web', version: SPRING_VERSION
compile group: 'org.springframework', name: 'spring-jdbc', version: SPRING_VERSION
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.5.RELEASE'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.5.2'
compile group: 'com.zaxxer', name: 'HikariCP', version: '3.2.0'
compile group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: '2.3.0'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: JACKSON_VERSION
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: JACKSON_VERSION
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: JUNIT_VERSION
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: JUNIT_VERSION
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.1'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.22.0'
testCompile group: 'org.springframework', name: 'spring-test', version: SPRING_VERSION
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testCompile group: 'com.jayway.jsonpath', name: 'json-path-assert', version: '2.4.0'
}
test {
useJUnitPlatform()
}
Scanning internet not helped. Please advice how to run it correctly. I had problems with downloading dependencies from jcenter(), may be, problem is here.
Validator write that my question have mostly code, but I have no Idea what to add to my explain, than, my apologies, I'll quote Steve Jobs:
“You can’t connect the dots looking forward; you can only connect them looking backward. So you have to trust that the dots will somehow connect in your future.”
You introduced a JEP-238 Jar file into your project: log4j-api-2.10.0.jar
Support for JEP-238 Jar files on any Java Runtime (doesn't matter if it's Java 7, Java 8, Java 9, Java 10, Java 11, or even the new Java 12-ea releases) was first introduced in Jetty 9.4.9.
You have 2 options:
Don't use JEP-238 Jar Files in your project.
Upgrade to Jetty 9.4.9 (or newer) to have support for JEP-238 Jar Files.
See past answers:
https://stackoverflow.com/a/45362629/775715
https://stackoverflow.com/a/52722120/775715

Log4j2 + MongoDb not work

I try to configure log4j2 to use MongoDB in a gradle project, when I run in Eclipse and my tests it's work fine, but When I generate a jar and start it I get a error:
2018-08-13 09:30:11,534 main ERROR Unable to locate plugin type for MongoDb
2018-08-13 09:30:11,548 main ERROR Unable to locate plugin for MongoDb
2018-08-13 09:30:11,597 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:181)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.(Main.java:15)
2018-08-13 09:30:11,607 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.(Main.java:15)
2018-08-13 09:30:11,617 main ERROR Null object returned for NoSql in appenders.
2018-08-13 09:30:11,655 main ERROR Unable to locate appender "NoSql" for logger config "root"
my log4j2.yaml:
Configuration:
status: WARN
appenders:
NoSql:
name: NoSql
MongoDb:
databaseName: tracker
collectionName: appLog
server: ds261755.mlab.com
port: 61755
username: admin
password: XXXXX
Loggers:
logger:
-
name: com.memorynotfound
level: info
-
name: com.mchange.v2.c3p0
level: warn
Root:
level: info
AppenderRef:
ref: NoSql
my buil.gradle:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
jar {
dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-nosql:2.9.1"
compile "org.apache.logging.log4j:log4j-jcl:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
compile group: 'org.mongodb', name: 'mongo-java-driver', version: '3.8.0'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}
My problem is in configuration? What I need to do?
[EDITED]
I change some configurations:
build.gradle:
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
jar {
//dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
mongoDBVersion = '3.8.0'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-jcl:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-mongodb3:${log4jVerison}"
//compile "org.apache.logging.log4j:log4j-nosql:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
//compile "org.mongodb:mongo-java-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver-core:${mongoDBVersion}"
compile "org.mongodb:bson:${mongoDBVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}
log4j2.yaml:
Configuration:
status: WARN
appenders:
NoSql:
name: databaseAppender
MongoDb3:
databaseName: tracker
collectionName: appLog
server: ds261755.mlab.com
port: 61755
username: admin
password: xxxx
Loggers:
logger:
-
name: com.memorynotfound
level: info
-
name: com.mchange.v2.c3p0
level: warn
Root:
level: info
AppenderRef:
ref: databaseAppender
and I get a new error message:
2018-08-14 10:29:26,690 main ERROR Unable to locate plugin type for MongoDb3
2018-08-14 10:29:26,703 main ERROR Unable to locate plugin for MongoDb3
2018-08-14 10:29:26,753 main ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.NullPointerException java.lang.NullPointerException
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.findNamedNode(PluginElementVisitor.java:103)
at org.apache.logging.log4j.core.config.plugins.visitors.PluginElementVisitor.visit(PluginElementVisitor.java:87)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:181)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.<clinit>(Main.java:15)
2018-08-14 10:29:26,764 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender for element NoSql: java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender java.lang.IllegalStateException: No factory method found for class org.apache.logging.log4j.core.appender.nosql.NoSqlAppender
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.findFactoryMethod(PluginBuilder.java:235)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:135)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:619)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:636)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:231)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:581)
at br.com.serversocket.main.Main.<clinit>(Main.java:15)
2018-08-14 10:29:26,773 main ERROR Null object returned for NoSql in appenders.
2018-08-14 10:29:26,813 main ERROR Unable to locate appender "databaseAppender" for logger config "root"
I inspected class' log4j-core to try understend better about the error and found this method:
protected void preConfigure(final Node node) {
try {
for (final Node child : node.getChildren()) {
if (child.getType() == null) {// problem happen here in production
LOGGER.error("Unable to locate plugin type for " + child.getName());
continue;
}
final Class<?> clazz = child.getType().getPluginClass();
if (clazz.isAnnotationPresent(Scheduled.class)) {
configurationScheduler.incrementScheduledItems();
}
preConfigure(child);
}
} catch (final Exception ex) {
LOGGER.error("Error capturing node data for node " + node.getName(), ex);
}
}
When I run project in IDE a node's property "getType()" is "PluginType [pluginClass=class org.apache.logging.log4j.mongodb3.MongoDbProvider, key=mongodb3, elementName=MongoDb3, isObjectPrintable=true, isDeferChildren==false, category=core]"
but I production, I suppose how the jar not found a class inside log4j-mongodb3.
I inspect generated jar, but the class was packaged without problems. what is happen ?
[EDITED]
I found my problem, I created a test project without gradle and I generated a jar, I need to copy dependencies and not extract they, how can I configure gradle to do it in jar task ?
I solved my problem using 2 gradle's plugin:
shadow:
http://imperceptiblethoughts.com/shadow/#shadowing_gradle_plugins
and this plugin to fix a incompability with log4j:
https://github.com/TheBoegl/shadow-log4j-transformer#using-the-gradle-plugin-dsl
follow my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
classpath 'de.sebastianboegl.gradle.plugins:shadow-log4j-transformer:2.2.0'
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'com.github.johnrengelman.shadow'
archivesBaseName = 'ServerSocket'
version = '3.2.1'
mainClassName = 'br.com.serversocket.main.Main'
compileTestJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
compileJava {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
shadowJar {
//dependsOn 'test'
transform(de.sebastianboegl.gradle.plugins.shadow.transformers.Log4j2PluginsFileTransformer)
archiveName = "ServerSocket.jar"
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
jar {
//dependsOn 'test'
archiveName = "ServerSocket.jar"
from {
configurations.runtime.collect {
it.isDirectory() ? it : zipTree(it)
}
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
manifest {
attributes 'Main-Class': 'br.com.serversocket.main.Main'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
}
test{
useJUnitPlatform()
dependsOn 'cleanTest'
testLogging {
events "passed", "skipped", "failed"
}
afterTest { desc, result ->
logger.quiet "Executing test ${desc.name} [${desc.className}] with result: ${result.resultType}"
}
testLogging {
exceptionFormat = 'full'
}
}
eclipse.classpath.file.whenMerged {
entries.each { println it.path }
}
configurations {
providedCompile
}
repositories {
mavenCentral()
mavenLocal()
}
ext {
jacksonVersion = '2.9.1'
hibernateVerison = '5.1.0.Final'
slf4jVerison = '1.7.25'
log4jVerison = '2.11.1'
junitVersion = '5.2.0'
emailVersion = '1.6.1'
mongoDBVersion = '3.8.0'
}
dependencies {
//compile files(fileTree(dir: 'lib', includes: ['*.jar']))
compile "org.hibernate:hibernate-jpamodelgen:${hibernateVerison}"
compile "org.hibernate:hibernate-c3p0:${hibernateVerison}"
compile "org.hibernate:hibernate-core:${hibernateVerison}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVerison}"
compile "org.slf4j:slf4j-simple:${slf4jVerison}"
compile "org.slf4j:slf4j-api:${slf4jVerison}"
compile "org.apache.logging.log4j:log4j-api:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-core:${log4jVerison}"
compile "org.apache.logging.log4j:log4j-mongodb3:${log4jVerison}"
compile "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
compile "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:${jacksonVersion}"
compile "javax.mail:javax.mail-api:${emailVersion}"
compile "com.sun.mail:javax.mail:${emailVersion}"
compile "org.mongodb:mongodb-driver:${mongoDBVersion}"
compile "org.mongodb:mongodb-driver-core:${mongoDBVersion}"
compile "org.mongodb:bson:${mongoDBVersion}"
compile group: 'org.projectlombok', name: 'lombok', version: '1.18.2'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.21'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.44'
compile group: 'org.hibernate.common', name: 'hibernate-commons-annotations', version: '5.0.1.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'com.mchange', name: 'c3p0', version: '0.9.2.1'
compile group: 'org.eclipse.persistence', name: 'javax.persistence', version: '2.1.0'
compile group: 'org.jboss.logging', name: 'jboss-logging', version: '3.3.1.Final'
compile group: 'commons-logging', name: 'commons-logging', version: '1.0.3'
compile group: 'org.apache.mina', name: 'mina-core', version: '2.0.19'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'com.fasterxml', name: 'classmate', version: '1.3.0'
compile group: 'commons-codec', name: 'commons-codec', version: '1.11'
compile group: 'commons-beanutils', name: 'commons-beanutils', version: '1.6'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2.1'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.5'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'commons-lang', name: 'commons-lang', version: '2.3'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.2'
compile group: 'dom4j', name: 'dom4j', version: '1.6.1'
compile group: 'net.sf.ehcache', name: 'ehcache', version: '1.5.0'
compile group: 'org.apache.geronimo.specs', name: 'geronimo-jta_1.1_spec', version: '1.1.1'
compile group: 'org.jboss', name: 'jandex', version: '2.0.3.Final'
compile group: 'org.javassist', name: 'javassist', version: '3.22.0-GA'
compile group: 'jdom', name: 'jdom', version: '1.1'
compile group: 'javax.transaction', name: 'jta', version: '1.1'
compile group: 'com.vividsolutions', name: 'jts', version: '1.13'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'com.mchange', name: 'mchange-commons-java', version: '0.2.3.4'
testCompile group: 'com.h2database', name: 'h2', version: '1.4.197'
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testCompile "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
testCompile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.2.0'
}
configurations {
all*.exclude group: 'javassist', module: 'javassist'
}

Using "gradle-3.5" to build web application but always fail in JPA

I was tried to build a web application by Gradle and pack a war file.
build.gradle
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
sourceCompatibility = 1.8
version = '1.0'
compileJava.options.encoding='UTF-8'
webAppDirName = 'fbs-report' //set webapp root
sourceSets {
main {
java {
srcDir 'src'
exclude '**/SlablistDload1Controller.java'
exclude '**/SlablistDload2Controller.java'
exclude '**/DormantDownloadController.java'
exclude '**/NewnewController.java'
}
resources {
srcDir 'config' //prorperties
}
}
}
repositories {
maven { url "http://maven.springframework.org/milestone" }
maven { url "http://repo.maven.apache.org/maven2" }
maven { url "http://repo1.maven.org/maven2/" }
maven { url "http://amateras.sourceforge.jp/mvn/" }
maven { url "http://repo.springsource.org/libs-release"}
mavenCentral()
}
configurations {
compile.exclude group: 'org.freemarker', module: 'freemarker'
compile.exclude group: 'javax.servlet', module: 'servlet-api'
compile.exclude group: 'jboss', module: 'javassist'
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile fileTree(include: ['*.jar'], dir: 'libs')
//spring framework
compile group: 'org.springframework', name: 'spring-context', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-test', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-beans', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-jdbc', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-aop', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-oxm', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-messaging', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-websocket', version: '4.3.7.RELEASE'
compile group: 'org.springframework', name: 'spring-instrument', version: '4.3.7.RELEASE'
//spring data
compile group: 'org.springframework.data', name: 'spring-data-commons', version: '1.12.6.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.1.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-rest-webmvc', version: '2.5.6.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-rest-core', version: '2.5.6.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-jdbc-core', version: '1.2.1.RELEASE'
compile group: 'org.springframework.data', name: 'spring-cql', version: '1.4.6.RELEASE'
compile group: 'org.springframework.data', name: 'spring-data-rest-parent', version: '2.5.6.RELEASE'
//spring-ws
compile group: 'org.springframework.ws', name: 'spring-xml', version: '2.4.0.RELEASE'
compile group: 'org.springframework.ws', name: 'spring-ws-security', version: '2.4.0.RELEASE'
compile group: 'org.springframework.ws', name: 'spring-ws-test', version: '2.4.0.RELEASE'
compile group: 'org.springframework.ws', name: 'spring-ws-support', version: '2.4.0.RELEASE'
//spring-boot
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.5.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '1.4.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.5.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-websocket', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-log4j', version: '1.3.8.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-test', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-deployment-tests', version: '1.4.2.RELEASE'
//compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '1.4.2.RELEASE'
//hibernate
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.3.3.Final'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-jpamodelgen', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-search-orm', version: '5.5.5.Final'
compile group: 'org.hibernate', name: 'hibernate-tools', version: '5.1.0.Final'
compile group: 'org.hibernate', name: 'hibernate-testing', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-infinispan', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-cdi', version: '5.3.3.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-annotation-processor', version: '5.3.3.Final'
compile group: 'org.hibernate.hql', name: 'hibernate-hql-parser', version: '1.3.0.Final'
compile group: 'org.hibernate.hql', name: 'hibernate-hql-testing', version: '1.3.0.Final'
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-osgi', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-test-utils', version: '5.3.3.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-osgi', version: '5.3.3.Final'
compile group: 'org.hibernate', name: 'hibernate-gradle-plugin', version: '5.2.5.Final'
compile group: 'org.hibernate', name: 'hibernate-validator-parent', version: '5.3.3.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.0.Final'
//compile group: 'javax.persistence', name: 'persistence-api', version: '1.0.2'
compile group: 'org.projectlombok', name: 'lombok', version: '1.16.16'
//apache common
compile group: 'javax.activation', name: 'activation', version: '1.1.1'
compile group: 'org.apache.activemq', name: 'activemq-core', version: '5.7.0'
compile group: 'org.apache.activemq.protobuf', name: 'activemq-protobuf', version: '1.1'
compile group: 'annogen', name: 'annogen', version: '0.1.0'
compile group: 'antlr', name: 'antlr', version: '2.7.7'
compile group: 'aopalliance', name: 'aopalliance', version: '1.0'
compile group: 'org.aspectj', name: 'aspectjrt', version: '1.8.10'
compile group: 'org.aspectj', name: 'aspectjweaver', version: '1.8.10'
compile group: 'org.apache.ws.commons.axiom', name: 'axiom-api', version: '1.2.20'
compile group: 'org.apache.axis2', name: 'axis2', version: '1.4.1'
compile group: 'org.apache.axis2', name: 'axis2-saaj', version: '1.4.1'
compile group: 'org.apache.commons', name: 'commons-pool2', version: '2.4.2'
compile group: 'org.apache.poi', name: 'poi', version: '3.9'
//compile group: 'org.quartz-scheduler', name: 'quartz', version: '2.2.3'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
compile group: 'net.sf.json-lib', name: 'json-lib', version: '2.4', classifier: 'jdk15'
//compile group: 'oro', name: 'oro', version: '2.0.8'
//compile group: 'org.freemarker', name: 'freemarker', version: '2.3.23'
//compile group: 'jboss', name: 'javassist', version: '3.22.0-CR1'
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.2'
compile group: 'commons-io', name: 'commons-io', version: '2.5'
compile group: 'org.jfree', name: 'jcommon', version: '1.0.23'
compile group: 'org.jfree', name: 'jfreechart', version: '1.0.19'
compile group: 'net.minidev', name: 'json-smart', version: '1.0.9'
compile group: 'xerces', name: 'xercesImpl', version: '2.11.0'
}
When I execute $ gradle build, always fail in task "compilejava"
Here is part of the error mesage:
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:62: error: cannot find symbol
classes={
^
symbol: method classes()
location: #interface SqlResultSetMapping
D:\fbs-UAT\fbs-report\src\model\ConvertModel.java:114: error: cannot find symbol
#OneToMany(cascade= { CascadeType.ALL }, fetch=FetchType.EAGER, orphanRemoval=true)
^
symbol: method orphanRemoval()
location: #interface OneToMany
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:66: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysId", type=Long.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:66: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysId", type=Long.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:67: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysCreateUser", type=String.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:67: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysCreateUser", type=String.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:68: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysCreateTime", type=Date.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:68: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysCreateTime", type=Date.class),
^
D:\fbs-UAT\fbs-report\src\MonitorModel.java:69: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysModifyUser", type=String.class),
^
D:\fbs-UAT\fbs-report\src\model\MonitorModel.java:69: error: duplicate element '<any?>' in annotation #<any?>.
#ColumnResult(name="sysModifyUser", type=String.class),
^
By the way, if takes away codes for JPA, it turns out Successful results.
If you add the dependency on JPA 1.0.2 the compilation will fail since some of your annotations depend on JPA 2.1.
Since 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final' already contains the JPA 2.1 API you don't need a separate dependency on javax.persistence:persistence-api

Categories