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

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()
}

Related

java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext with Spring Boot 3 and Jetty server

I community, I'm trying to run a small example with Spring boot 3 and Jetty server before upgrading the production code but I'm getting this error java.lang.ClassNotFoundException: jakarta.servlet.http.HttpSessionContext and the services does not start. This is my Gradle config.
plugins {
id 'java'
id 'idea'
id 'org.springframework.boot' version '3.0.1'
id 'io.spring.dependency-management' version '1.1.0'
}
idea {
module {
downloadJavadoc = false
downloadSources = false
}
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-jetty'
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
and the dependeincies.
HttpSessionContext class no longer exists but somehow, the latest version Jetty still depends on it.
I'm expecting to make it run with Jetty without migrating to another server.
As Jaokim Erdfelt already mentioned, Spring Boot 3 rely on Jakarta Servlet 6.0.0 (see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Release-Notes) and the spring-boot-starter-jetty includes Jetty 11 which is build on Jakarta Servlet 5.0.0 (see https://java.libhunt.com/jetty-project-changelog/11.0.0). So this is an Issue in the starter itself.
To use jetty you have to downgrade the jakarta-servlet version (see https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#jetty) setting
ext["jakarta-servlet.version"] = "5.0.0"
Spring 3 is for Servlet 6 which is available in Jetty 12+

Could not resolve: org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE

what is the problem, i just changed group name here, i get could not resolve for springsecuriy extras
i can't see why
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.0'
id 'io.spring.dependency-management' version '1.1.0'
id 'org.hibernate.orm' version '6.1.5.Final'
id 'org.graalvm.buildtools.native' version '0.9.18'
}
group = '*********'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity6'
runtimeOnly 'org.mariadb.jdbc:mariadb-java-client'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
}
tasks.named('test') {
useJUnitPlatform()
}
hibernate {
enhancement {
lazyInitialization true
dirtyTracking true
associationManagement true
}
}
Could not resolve all files for configuration ':compileClasspath'. > Could not resolve org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE. Required by: project : > Could not resolve org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.0.RELEASE. > Could not parse POM repo.maven.apache.org/maven2/org/thymeleaf/extras/… > Could not find org.springframework.security:spring-security-bom:6.0.0-RC2
I tried nothing it is made by spring initializer and boot version 3.0.0
Thymeleaf 3.1.1 is released now, pls use
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity6:3.1.1.RELEASE")
instead of
implementation("org.thymeleaf.extras:thymeleaf-extras-springsecurity5")
I resolved problem by changing gradle build
i replaced repositories with this
repositories {
mavenCentral()
maven { url "https://repo.spring.io/milestone"
content {
// Thymeleaf uses 6.0.0-RC2 of Security's bom in its dependency management
includeModule("org.springframework.security", "spring-security-bom")
}
}
}
I hope it help others

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()
}

How to append timestamp to jar in spring boot gradle project?

How to append a timestamp to jar in the spring boot Gradle project?
./gradlew build
Creates jar app-0.0.1-SNAPSHOT.jar, how to create jar with timestamp
app-0.0.1-SNAPSHOT-2020-11-09.02-30.jar
-------- Gradle
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
test {
useJUnitPlatform()
}
How about
bootJar {
archiveFileName = "app-0.0.1-SNAPSHOT-"+new Date().format('yyyy-MM-dd.HH-mm')+ ".jar"
}
Tested with gradle 6.6.1 and spring boot plugin version 2.3.4

Spring boot with thymeleaf starter excludes javassist from other dependencies

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.

Resources