Building War file via including Avro auto generated classes - java

I've recently started using Avro and Kafka in my spring boot project. Now I've googled this and can't seem to find a straight answer.
When I build my war via my gradle build file, can I include the classes autogenerated from Avro schema?
Look at the war file when its exploded it doesnt seem to include those classes.
Here is my build.gradle file.
Many thanks for reading this question and if you have the time to help!
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 'com.test.tge-auth-service'
version '1.0'
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'
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'
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-data-jpa', version: '2.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', 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: '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: 'mysql', name: 'mysql-connector-java', version: '8.0.21'
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'
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.SpringBootPersistenceApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}

Ok so, for me what worked was a rebuild of the project in Intellij.

Related

Java - Hibernate envers not working in Jar

We use Hibernate Envers for keeping object change history. It's been working fine in development, now that we've build a JAR out of the code it does not work anymore. We've tried numerous things, like upgrading, checking if the database connection is right etc. Everything works fine when running in Intellij itself, just not when running the compiled JAR.
We get the issue when initialising the Hibernate session factory, we've not done any transactions when getting this error. A lot of answers online have a solution for the context wherein a session is not accessed correctly, this is not the case here.
The build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'idea'
apply plugin: 'kotlin'
group = 'com.obscured'
version = '1.0'
description = "Obscured API"
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
maven { url 'https://maven.google.com' }
mavenCentral()
jcenter()
}
dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'commons-codec', name: 'commons-codec', version: '1.10'
implementation group: 'com.sparkjava', name: 'spark-core', version: '2.9.3'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5'
implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.5'
implementation group: 'org.json', name: 'json', version: '20170516'
implementation group: 'de.mkammerer', name: 'argon2-jvm', version: '2.2'
implementation group: 'com.maxmind.geoip2', name: 'geoip2', version: '2.9.0'
implementation group: 'javax.mail', name: 'mail', version: '1.4'
implementation group: 'com.stripe', name: 'stripe-java', version: '16.1.0'
implementation group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer', version: '20191001.1'
implementation group: 'com.google.code.geocoder-java', name: 'geocoder-java', version: '0.16'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.18'
implementation group: 'org.flywaydb', name: 'flyway-core', version: '5.1.4'
implementation group: 'org.hibernate', name: 'hibernate-core', version: '5.4.30.Final'
implementation group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.4.30.Final'
implementation group: 'org.hibernate', name: 'hibernate-c3p0', version: '5.4.30.Final'
implementation group: 'org.hibernate', name: 'hibernate-ehcache', version: '5.4.30.Final'
implementation group: 'org.hibernate', name: 'hibernate-envers', version: '5.4.30.Final'
implementation group: 'org.hibernate.search', name: 'hibernate-search-mapper-orm', version: '6.0.1.Final'
implementation group: 'org.hibernate.search', name: 'hibernate-search-backend-lucene', version: '6.0.1.Final'
implementation group: 'com.google.firebase', name: 'firebase-admin', version: '7.0.0'
implementation group: 'com.github.hotchemi', name: 'khronos', version: '0.9.0'
implementation group: 'org.everit.json', name: 'org.everit.json.schema', version: '1.5.1'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.11.3'
implementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.688'
implementation 'com.google.maps:google-maps-services:0.11.0'
implementation 'com.google.firebase:firebase-admin:6.12.2'
implementation 'com.auth0:java-jwt:3.10.3'
implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'
implementation group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1.1'
// Swagger
implementation group: 'io.swagger.core.v3', name: 'swagger-core', version: '2.1.6'
implementation group: 'io.swagger.core.v3', name: 'swagger-jaxrs2', version: '2.1.6'
implementation group: 'io.swagger.core.v3', name: 'swagger-jaxrs2-servlet-initializer', version: '2.1.6'
implementation group: 'io.swagger.core.v3', name: 'swagger-annotations', version: '2.1.4'
implementation 'io.github.cdimascio:java-dotenv:3.0.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
task fatJar(type: Jar) {
zip64 = true
archiveName = 'obscured.jar'
manifest {
attributes 'Main-Class': 'com.obscured.Obscured'
}
exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
with jar
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin/'
test.java.srcDirs += 'src/test/kotlin/'
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
The command we run (in the main directory, just to be safe):
java -jar obscured.jar
The code being executed where the error occurs:
try {
val cfg = Configuration()
cfg.configure("db/hibernate.cfg.xml")
cfg.setProperty("hibernate.connection.url", "jdbc:mysql://" + this.host + ":" + this.port?.toString() + "/" + this.database + "?autoReconnect=true")
cfg.setProperty("hibernate.connection.username", this.username)
cfg.setProperty("hibernate.connection.password", this.password)
factory = cfg.buildSessionFactory()
} catch (ex: Throwable) {
System.err.println("Failed user create sessionFactory object.$ex")
throw ExceptionInInitializerError(ex)
}
The error we're getting:
Caused by: org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.envers.boot.internal.EnversService]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.envers.boot.internal.TypeContributorImpl.contribute(TypeContributorImpl.java:22)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:391)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:132)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:86)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at com.obscured.database.Connection.configureHibernate(Connection.kt:69)
... 2 more
Again, this just seems to be happening once it is in a JAR, all dependencies are available and doing just fine. We've tried using several different versions of Hibernate dependencies, however this seems to be an issue for us across the board.
We even decompiled the JAR to see if the same files are there as they are in our IDE, and they are, so no luck there. We've obviously search the internet for answers with no positive result.

Gradle cannot build JAR with dependecies for Docker

I have a Spring MVC application that I want to add to Docker. I created the image, configured Docker, but the application in Docker does not want to start. How can I fix the problem?
I tried different ways to fix this error, for example, I added the following code to gradle.build:
dependencies {
extraLibs group: 'net.java.dev.jna', name: 'jna-platform', version: '4.2.2'
// ... dependencies ...
configurations.compile.extendsFrom(configurations.extraLibs)
}
But it didn't work.
GRADLE:
plugins {
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
//configurations {
// configuration that holds jars to include in the jar
// extraLibs
//}
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
//
jar {
manifest {
attributes "Main-Class": 'ru.coffeetearea.CoffeeTeArea'
}
}
ext {
javaMainClass = "ru.coffeetearea.CoffeeTeArea"
}
task fatJar(type: Jar) {
classifier = 'all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
dependencies {
// extraLibs group: 'net.java.dev.jna', name: 'jna-platform', version: '4.2.2'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.3.3.RELEASE'
// Thymeleaf
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: '2.3.3.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-validation
compile group: 'org.springframework.boot', name: 'spring-boot-starter-validation', version: '2.3.3.RELEASE'
// Swagger UI
compile group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
// Swagger 2
compile group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot
compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
compile group: 'org.postgresql', name: 'postgresql', version: '42.2.14'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.3.1.RELEASE'
// https://mvnrepository.com/artifact/org.flywaydb/flyway-core
compile group: 'org.flywaydb', name: 'flyway-core', version: '6.5.1'
// MapStruct
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
// https://mvnrepository.com/artifact/org.projectlombok/lombok
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
// https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-jpamodelgen
annotationProcessor('org.hibernate:hibernate-jpamodelgen:6.0.0.Alpha5')
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '2.3.2.RELEASE'
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
// JUnit
testImplementation('org.junit.jupiter:junit-jupiter:5.6.2')
// https://mvnrepository.com/artifact/org.mockito/mockito-core
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.1.0'
// configurations.compile.extendsFrom(configurations.extraLibs)
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
DOCKERFILE:
FROM openjdk:11
ADD build/libs/Coffeetearea-0.0.1-SNAPSHOT.jar Coffeetearea-0.0.1-SNAPSHOT.jar
EXPOSE 5432
ENTRYPOINT ["java", "-jar", "Coffeetearea-0.0.1-SNAPSHOT.jar"]
Manifest.MF:
Manifest-Version: 1.0
Main-Class: ru.coffeetearea.CoffeeTeArea
ERRORS:
C:\Users\vartanyan\IdeaProjects\Coffeetearea>docker run -p 5432:5432 coffeetearea
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication
at ru.coffeetearea.CoffeeTeArea.main(CoffeeTeArea.java:12)
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
You are using Spring Boot in your application and in your build you are trying very hard to not use it. In short don't, use the Spring Boot Gradle plugin to build a proper jar
plugins {
id 'org.springframework.boot' version '2.3.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
dependencies {
// extraLibs group: 'net.java.dev.jna', name: 'jna-platform', version: '4.2.2'
// https://mvnrepository.com/artifact/org.apache.commons/commons-lang3
implementation group: 'org.apache.commons', name: 'commons-lang3', version:
'3.11'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation group: 'org.springframework.boot:spring-boot-starter-test'
// Swagger UI
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2'
// Swagger 2
implementation group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2'
// https://mvnrepository.com/artifact/org.postgresql/postgresql
implementation group: 'org.postgresql', name: 'postgresql'
// https://mvnrepository.com/artifact/org.flywaydb/flyway-core
implementation group: 'org.flywaydb', name: 'flyway-core'
// MapStruct
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
// https://mvnrepository.com/artifact/org.projectlombok/lombok
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
// https://mvnrepository.com/artifact/org.hibernate.orm/hibernate-jpamodelgen
annotationProcessor('org.hibernate:hibernate-jpamodelgen:6.0.0.Alpha5')
// https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt
compile group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
// https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.4.0-b180830.0359'
}
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
}
}
Now when you do ./gradlew build it will generate a proper Spring Boot jar that you can run on the command-line. This jar you can also use in your docker images.
As of Spring Boot 2.3 it is possible to let Spring Boot create the image as well using build packs or regular docker.
When using a build pack, the above build.gradle is enough to create an image. Just run ./gradlew bootBuildImage, it will then use build packs to generate an image.

AbstractMethodError: org.apache.bval.jsr303.ConfigurationImpl has missing definition for method getDefaultParameterNameProvider()

I am currently working on upgrading our Spring Boot (2.1.5) Application to gradle version '5.4.1' with JAVA 11.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: Receiver class org.apache.bval.jsr303.ConfigurationImpl does not define or inherit an implementation of the resolved method abstract getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; of interface javax.validation.Configuration.
Relevant Dependencies:
hibernate-core: 5.4.3.Final
hibernate-validator: 6.0.17.Final
I have tried downgrading hibernate-validator and tried explicitly specifying a version of validation-api but nothing seems to work.
Build.Gradle
buildscript {
ext {
springBootVersion = '2.1.5.RELEASE'
}
repositories {
mavenCentral()
jcenter()
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
compileJava {
sourceCompatibility = '11'
targetCompatibility = '11'
}
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'idea'
mainClassName = 'io.app.ams.Application'
bootJar {
mainClassName 'io.app.ams.Application'
launchScript()
}
springBoot {
mainClassName 'io.app.ams.Application'
buildInfo()
}
bootRun {
sourceResources sourceSets.main
}
apply from: 'liquibase.gradle'
apply from: 'gatling.gradle'
configurations {
providedRuntime
}
defaultTasks 'bootRun'
repositories {
mavenLocal()
maven { url 'http://repo.spring.io/milestone' }
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'https://repository.jboss.org/nexus/content/repositories/releases' }
maven { url 'https://oss.sonatype.org/content/repositories/releases' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'http://repo.maven.apache.org/maven2' }
flatDir {
dirs 'libs'
}
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-validation')
testImplementation 'org.scalatest:scalatest_2.11:3.0.0'
compile group: 'commons-httpclient', name: 'commons-httpclient', version: '3.1'
compile group: 'io.dropwizard.metrics', name: 'metrics-core'
compile group: 'io.dropwizard.metrics', name: 'metrics-graphite'
compile group: 'io.dropwizard.metrics', name: 'metrics-healthchecks'
compile group: 'io.dropwizard.metrics', name: 'metrics-jvm', version: dropwizard_metrics_version
compile group: 'io.dropwizard.metrics', name: 'metrics-servlet', version: dropwizard_metrics_version
compile group: 'io.dropwizard.metrics', name: 'metrics-json', version: dropwizard_metrics_version
compile group: 'io.dropwizard.metrics', name: 'metrics-servlets'
// kafka
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: kafka_version
compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.18'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-json-org', version: jackson_version
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hppc', version: jackson_version
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-joda'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-hibernate4', version: jackson_version
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jdk8'
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310'
compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-parameter-names'
compile(group: 'com.zaxxer', name: 'HikariCP', version: HikariCP_version) {
exclude(module: 'tools')
}
compile group: 'org.apache.commons', name: 'commons-lang3', version: commons_lang_version
compile group: 'commons-io', name: 'commons-io', version: commons_io_version
compile group: 'javax.inject', name: 'javax.inject', version: javax_inject_version
compile group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1'
compile group: 'joda-time', name: 'joda-time', version: '2.10.2'
compile group: 'org.apache.geronimo.javamail', name: 'geronimo-javamail_1.4_mail', version: geronimo_javamail_1_4_mail_version
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.4.3.Final'
compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.1.0.Alpha5'
compile group: 'org.hibernate', name: 'hibernate-envers', version: '5.4.3.Final'
compile group: 'org.hibernate', name: 'hibernate-ehcache' ,version: '5.4.3.Final'
compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.1-api', version: '1.0.2.Final'
compile group: 'org.jadira.usertype', name: 'usertype.core', version: '7.0.0.CR1'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.1.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '2.1.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-properties-migrator', version: '2.1.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure'
compile group: 'org.springframework.boot', name: 'spring-boot-loader-tools'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-logging'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-aop'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.1.6.RELEASE')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-websocket'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-velocity', version: '1.1.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-elasticsearch', version: '2.1.6.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb'
compile group: 'org.springframework.cloud', name: 'spring-cloud-cloudfoundry-connector'
compile group: 'org.springframework.cloud', name: 'spring-cloud-spring-service-connector'
compile group: 'org.springframework.cloud', name: 'spring-cloud-localconfig-connector'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-config', version: '2.1.3.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-dependencies', version: 'Greenwich.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.1.2.RELEASE'
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-zuul', version: '2.1.2.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot', version: '2.1.6.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.8.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support'
compile group: 'org.springframework.security', name: 'spring-security-core', version: spring_security_version
compile group: 'org.springframework.security', name: 'spring-security-config', version: spring_security_version
compile group: 'org.springframework.security', name: 'spring-security-data', version: spring_security_version
compile group: 'org.springframework.security', name: 'spring-security-web', version: spring_security_version
compile group: 'org.springframework.security', name: 'spring-security-messaging', version: spring_security_version
compile group: 'org.springframework.security', name: 'spring-security-acl', version: spring_security_version
compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version: spring_security_oauth2_version
compile group: 'org.springframework.ws', name: 'spring-ws-core', version: '3.0.7.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '8.0.16'
compile group: 'com.h2database', name: 'h2'
compile group: 'org.kairosdb', name: 'client', version: '3.0.0'
compile group: 'org.projectlombok', name: 'lombok', version: lombok_version
compile group: 'org.apache.commons', name: 'commons-lang3', version: commons_lang3_version
compile group: 'commons-validator', name: 'commons-validator', version: commons_validator_version
compile group: 'io.jsonwebtoken', name: 'jjwt', version: jjwt_version
runtime "net.java.dev.jna:jna"
optional "org.springframework.boot:spring-boot-configuration-processor"
}
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
mavenBom 'org.springframework:spring-framework-bom:5.1.8.RELEASE'
}
}
compileJava.dependsOn(processResources)
wrapper {
gradleVersion = '5.4.1'
distributionUrl = distributionUrl.replace("bin", "all")
}
The error is linked to bval (apache bean validation implementation), the one you have targets bean validation 1.0. you can upgrade it to bval-jsr for a bean validation 1.1 implementation or exclude/drop it if you want hibernate instead.
Side note: if you are in an old tomee it requires some system.properties tuning if i recall correctly.

Updating build.gradle removes libraries from classpath

I have created spring mvc project with gradle and I have the following problem.
I know solution of this problem is simple but I haven't found it yet.
this is code in HibernateConfiguration.java:
this is build.gradle file:
plugins {
id 'java'
id 'war'
}
group 'com.gtu.gtesting'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
//---
testCompile group: 'org.springframework', name:'spring-core', version:'5.1.2.RELEASE'
testCompile group: 'org.springframework', name:'spring-tx', version:'5.1.2.RELEASE'
testCompile group: 'org.springframework', name:'spring-beans', version:'5.1.2.RELEASE'
testCompile group: 'org.springframework', name:'spring-orm', version:'5.1.2.RELEASE'
testCompile group: 'org.springframework', name: 'spring-mvc', version: '5.1.2.RELEASE'
testCompile group: 'org.springframework', name: 'spring-webmvc', version: '5.1.2.RELEASE'
testCompile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.7.Final'
testCompile group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'
testCompile group: 'javax.servlet', name: 'jstl', version: '4.0.1'
testCompile group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
testCompile group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
testCompile group: 'javax.persistence', name: 'persistence-api', version: '1.0.2'
testCompile group: 'javax.servlet', name: 'servlet-api', version: '3.0-alpha-1'
}
After I update build.gradle file (for example after add/remove dependency):
I get unresolved symbols in every file:
Change testCompile group group to compile group

Remove all unnecessary libs from fat jar

I'm writing java console application using Spring Boot Jpa and MySQL connector. How I can easily exclude all unnecessary libs from my fat jar?
build.gradle
buildscript {
ext {
springBootVersion = '1.5.9.RELEASE'
}
repositories {
// mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'ca.cutterslade.gradle:gradle-dependency-analyze:1.2.0'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'ca.cutterslade.analyze'
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
mysqlVersion = '6.0.6'
hibernateVersion = '5.2.12.Final'
}
repositories {
mavenCentral()
}
dependencies {
// compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.12.Final'
// compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.12.Final'
// compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
// compile group: 'org.springframework.boot', name: 'spring-boot', version: '1.5.9.RELEASE'
// compile group: 'org.hibernate.javax.persistence', name: 'hibernate-jpa-2.0-api', version: '1.0.0.Final'
// compile group: 'org.springframework', name: 'spring-context', version: '4.3.13.RELEASE'
// compile group: 'org.springframework', name: 'spring-beans', version: '4.3.13.RELEASE'
// compile group: 'org.springframework.boot', name: 'spring-boot-autoconfigure', version: '1.5.9.RELEASE'
// compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
// compile group: 'org.springframework', name: 'spring-tx', version: '2.5.4'
// compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.9.RELEASE'
// testCompile group: 'org.springframework.boot', name: 'spring-boot-test', version: '1.5.9.RELEASE'
// testCompile group: 'junit', name: 'junit', version: '4.12'
// testCompile group: 'org.springframework', name: 'spring-test', version: '4.3.13.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: mysqlVersion
compile group: 'org.hibernate', name: 'hibernate-core', version: hibernateVersion
compile("org.springframework.boot:spring-boot-starter-data-jpa")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
jar {
baseName 'ReportGenerator'
version '1.0'
}
UPDATE
I have tried to use gradle-dependency-analyze and received the following result:
usedUndeclaredArtifacts:
- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
- org.springframework.boot:spring-boot:1.5.9.RELEASE
- org.springframework:spring-context:4.3.13.RELEASE
- org.springframework:spring-beans:4.3.13.RELEASE
- org.springframework.boot:spring-boot-autoconfigure:1.5.9.RELEASE
- org.slf4j:slf4j-api:1.7.25
- org.springframework:spring-tx:4.3.13.RELEASE
- org.springframework.data:spring-data-jpa:1.11.9.RELEASE
unusedDeclaredArtifacts:
- mysql:mysql-connector-java:6.0.6
- org.hibernate:hibernate-core:5.2.12.Final
- org.springframework.boot:spring-boot-starter-data-jpa:1.5.9.RELEASE
As you see unused libraries are marked all libraries in my gradle at the moment. And required librariesare marked only which are used in the scope of my classes in app but don't get me know what these required libraries depends on also. If I will put only these list of required dependencies in the gradle then I will get different initialization errors since some libraries are missed.
Couple of suggestions.
Use dependency:analyze on your project which will list the unused dependencies, which you can exclude or get rid of.
use the <scope> attribute for each and every dependency in your pom, which can greatly reduce your fat jar size. Provide correct scope parameters, like compile, test .....

Categories

Resources