Spring boot with thymeleaf starter excludes javassist from other dependencies - spring-boot

I have 2 project, the 1st project is depending on javassist and 2nd project is dependint on the 1st and spring-boot-starter-thymeleaf.
The build gradle is like below
1st project
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation 'org.javassist:javassist:3.27.0-GA'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
The 2nd project is like below, :bar:hoge is the 1st project.
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation project(':bar:hoge')
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
bootJar {
mainClassName = 'com.example.koji.Main'
}
If I run the ../gradlew dependencyInsight --dependency javassist --configuration runtimeClasspath, The result is like below.
No dependencies matching given input were found in configuration ':foo:bar:runtimeClasspath'
And gradlew assemble doesn't have javassist.
But If I removed id 'org.springframework.boot' version '2.3.3.RELEASE' from 1st project or implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' from 2nd project, then same command will return like below
org.javassist:javassist:3.27.0-GA
\--- project :bar:hoge
\--- runtimeClasspath
And gradlew assemble jar has javassist.
Any ideas? Now I need to add javassist dependency at 2nd project explicitly to solve it.
Working project https://github.com/kojilin/example-multi

Maybe the reason comes from here?
https://github.com/gradle/gradle/issues/1473#issuecomment-413333723
so if I applied
dependencyManagement {
applyMavenExclusions = false
}
It will preserve the library in runtimeClasspath.

If you want to automatically inherit the javassist dependency from :bar:hoge, declare it as api, not implementation.

Related

getting springboot to support groovy 4.0 (apache packaging) | needed 3.0.0-M2 and more

spring-boot > 2.3.1 will grab groovy-bom from codehaus instead of org.apache.groovy packaging, even if you declare org.apache.groovy dependendices
I found this means spring-boot > 2.3.1 will not build groovy 4.0
even spring initializr bakes this in... because when you go springboot 2.6.7, initializr is using groovy packaging from org.codehaus. so that limits 2.6.7 to use groovy 3.0.10, as that's the cutoff for groovy to show up in org.apache packaging. and groovy 4.x uses apache packages.
here's the gradle initializr created from this URL
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.codehaus.groovy:groovy'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Support for Groovy 4 is coming in Spring Framework 6 and Spring Boot 3. It’s currently available in Spring Boot 3.0.0-M2 which is published to https://repo.spring.io/milestone.
you 1st have to change settings.gradle to add the following:
pluginManagement {
repositories {
maven { url 'https://repo.spring.io/milestone' }
gradlePluginPortal()
}
}
Then I had to modify my build.gradle as follows:
plugins {
// id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'groovy'
}
plugins {
id 'org.springframework.boot' version '3.0.0-M2'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = javaSrcVersion
targetCompatibility = javaClassVersion
repositories {
mavenCentral()
maven { url("https://repo.spring.io/milestone/")}
}
dependencies {
runtimeOnly('com.h2database:h2')
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
// implementation 'org.codehaus.groovy:groovy'
implementation("org.apache.groovy:groovy:${groovyVersion}")
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('com.google.code.findbugs:jsr305:latest.integration')
implementation group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
implementation group: 'jakarta.persistence', name: 'jakarta.persistence-api', version: '3.1.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.11.0'
testImplementation("org.testng:testng:${testNgVersion}")
}
tasks.named('test') {
useJUnitPlatform()
}

Build failed Spring Boot Plugin was not found

I download a repo 'gs-handling-form-submission' from spring.io and now I'm trying to build: gradle build
Following Error has being triggered
* Where:
Build file 'C:\Users\Username\Desktop\gs-handling-form-submission\complete\build.gradle' line: 11
* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.4.2'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.4.2')
Searched in the following repositories:
Gradle Central Plugin Repository
I already added a repo url, changed spring.boot version, added buildscript.repositories() at the first line, even doing that, I can't get to compile.
plugins {
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
mavenCentral()
maven {
url: "https://plugins.gradle.org/m2/"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}
Fixing the build.gradle, removing : url, was possible to build
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
test {
useJUnitPlatform()
}

Spring Boot Multi Module Gradle Project classpath problem: Package Not Found, Symbol not Found

I have an spring boot gradle project etl with a dependency of common core classes in another project named common.
common/build.gradle
plugins {
id 'net.ltgt.apt' version '0.21'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
id "io.freefair.lombok" version "5.1.0"
id 'java'
id 'idea'
id 'eclipse'
}
group = 'com.intelease'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
mavenCentral()
maven {
name "lightbend-maven-release"
url "https://repo.lightbend.com/lightbend/maven-releases"
}
maven {
name "Sonatype Snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots/"
}
ivy {
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
}
}
dependencies {
implementation 'com.typesafe.play:play-java_2.13:2.7.3'
implementation 'com.typesafe.akka:akka-actor-typed_2.13:2.5.23'
implementation "com.typesafe.play:play-guice_2.12:2.6.15"
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.neo4j.driver:neo4j-java-driver:1.7.5'
implementation 'org.apache.poi:poi-ooxml:3.17'
implementation 'com.google.maps:google-maps-services:0.13.0'
implementation 'org.apache.commons:commons-text:1.8'
implementation 'com.google.cloud:google-cloud-language:1.19.0'
implementation 'com.google.cloud:google-cloud-vision:1.19.0'
implementation 'technology.tabula:tabula:1.0.2'
implementation 'com.amazonaws:aws-java-sdk:1.11.618'
implementation 'edu.stanford.nlp:stanford-corenlp:3.8.0'
implementation 'nz.ac.waikato.cms.weka:weka-stable:3.8.4'
// https://mvnrepository.com/artifact/com.typesafe.play/play-java
implementation 'org.joda:joda-money:0.11'
implementation 'com.feth:play-easymail_2.12:0.9.0'
implementation 'com.feth:play-authenticate_2.12:0.9.0'
implementation 'org.apache.commons:commons-imaging:1.0-alpha1'
implementation 'com.github.cloudyrock.mongock:mongock-core:3.3.2'
implementation 'com.github.cloudyrock.mongock:mongock-spring:3.3.2'
implementation 'net.logstash.logback:logstash-logback-encoder:5.3'
implementation 'ch.qos.logback:logback-core:1.2.3'
implementation 'ch.qos.logback:logback-classic:1.2.3'
implementation 'com.google.firebase:firebase-admin:6.13.0'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
implementation 'org.jgrapht:jgrapht-core:1.4.0'
implementation 'org.jgrapht:jgrapht-io:1.4.0'
implementation 'commons-io:commons-io:2.6'
implementation 'org.springframework.guice:spring-guice:1.1.4.RELEASE'
implementation 'com.google.inject:guice:4.2.3'
implementation 'commons-collections:commons-collections:3.2.2'
implementation 'org.aspectj:aspectjrt:1.9.5'
implementation 'org.ghost4j:ghost4j:1.0.1'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' // if you are using mapstruct in test code
testImplementation 'io.projectreactor:reactor-test:3.3.0.RELEASE'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.2.0.RELEASE'
testImplementation 'cloud.localstack:localstack-utils:0.1.22'
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.3'
testImplementation 'net.aichler:jupiter-interface:0.8.3'
testImplementation 'org.mockito:mockito-junit-jupiter:3.0.0'
testImplementation 'org.assertj:assertj-core:3.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
}
etl/settings.gradle:
rootProject.name = 'etl'
includeFlat ('common')
etl/build.gradle:
plugins {
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'eclipse'
id 'idea'
id 'java'
}
group = 'com.intelease'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
jcenter()
maven {
name "lightbend-maven-release"
url "https://repo.lightbend.com/lightbend/maven-releases"
}
ivy {
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
}
}
ext {
set('springCloudVersion', "Hoxton.SR4")
}
dependencies {
implementation project(':common')
implementation 'org.apache.kafka:kafka-streams'
implementation 'io.debezium:debezium-core:1.1.1.Final'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka-streams'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.cloud:spring-cloud-stream-test-support'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
test {
useJUnitPlatform()
}
The etl project and common project are just side by side in the same level in file system.
The problem is that whenever I try to build the etl project which is dependent on common, It shows some problem regarding classes that I've expected to be brought and available from common project.
I've included the common into settings.gradle inside etl project with using includeFlat and Couldn't trace any issue with regard gradle multi module inclusion mechanisms.
Whats wrong with this flat multi module ecosystem?
the build script is ./gradlew clean build in the etl folder.
The problem was because of spring boot plugin being present in both etl and common projects. so I found out that in the cammon/build.gradle I have to add this piece of code:
...
bootJar {
enabled = false
}
jar {
enabled = true
}
...

Cannot change dependencies of configuration ':implementation' after it has been included in dependency resolution

I have got a very basic build.gradle file.
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
bootJar{
mainClassName = "$mainClassName";
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
I get the following error when bootJar task is placed before dependencies block. When placed after the dependencies block i don't get an error.
What went wrong:
A problem occurred evaluating root project 'sample-project-spring-boot'.
Cannot change dependencies of configuration ':implementation' after it has been included in dependency resolution.

Trying to modularize Gradle SpringBoot Project but getting "Error: cannot find symbol" when trying to build?

I had a working single-module Java project I am trying to break up into two modules: a library, and an application module. I pulled out the Java libraries from the top level build.gradle and stuffed them in the library build.gradle, and kept the SpringBoot/Docker/MySQL related dependencies in the application build file. Running ./gradlew build causes errors due to "cannot find symbol" errors on the lombok stuff in the App.
I added a top level settings.gradle (code below), pulled out all the Java libraries and put into the library/build.gradle (code below), and added a reference to library in the application/build.gradle (code below).
settings.gradle:
rootProject.name = 'order-routing'
include 'library'
include 'application'
library/build.gradle:
buildscript {
repositories { mavenCentral() }
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
}
apply plugin: 'project-report'
apply plugin: 'java'
ext { springBootVersion = '2.1.6.RELEASE' }
jar {
baseName = 'order-routing-library'
version = '0.0.1-SNAPSHOT'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
compileOnly 'com.google.code.gson:gson:2.8.5'
runtimeOnly 'com.h2database:h2:1.4.197'
compile 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'com.google.cloud.sql:mysql-socket-factory-connector-j-8:1.0.14'
}
and application/build.gradle (notice I added "compile project(':library')") :
buildscript {
ext { springBootVersion = '2.1.6.RELEASE' }
repositories { mavenCentral() }
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
plugins {
id "io.spring.dependency-management" version "1.0.5.RELEASE"
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
id "org.flywaydb.flyway" version "5.2.4"
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'project-report'
apply plugin: "maven"
apply plugin: 'docker'
repositories {
mavenCentral()
}
dependencies {
compile 'mysql:mysql-connector-java'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
compile project(':library')
}
sourceCompatibility = 8
targetCompatibility = 8
compileJava.options.compilerArgs.add '-parameters'
compileTestJava.options.compilerArgs.add '-parameters'
configurations {
all*.exclude group: "org.hibernate", module: "hibernate-entitymanager"
all*.exclude group: "org.apache.tomcat", module: "tomcat-jdbc"
}
flyway {
url = 'jdbc:mysql://localhost/ordb'
user = 'flyway'
table = 'schema_version'
}
bootJar {
baseName = 'order-routing-application'
version = '0.0.1-SNAPSHOT'
mainClassName = 'com.pokemonmerch.orderrouting.OrderRoutingApplication'
}
Expected result: run './gradlew build' and see a successful build.
Actual: Getting "error: cannot find symbol" on a bunch of lombok generated methods
As I understood you're trying to use lombok in the application module, but you added it as a compileOnly dependency to the library module. So, because it's compileOnly it's not passed as a transitive dependency to the application module.
Please add lombok dependecies to the application module directly or change compileOnly to compile(what I don't recommend to do).
P.S. Don't forget to turn on Annotation Processing in your IDE.
Actually, what I suggest - it's to create build.gradle in the root folder (order-routing/build.gradle) and move common dependencies there, under the subprojects sections (https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:subproject_configuration)

Resources