1

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()
}
Bob Makowski
  • 305
  • 2
  • 8
  • 1
    Thanks to Andy Wilkinson's tip, I started exploring springboot 3.0.0-M2. I got my spring-data-rest application to build and to run using groovy 4.0.2. but it took some source code changes because of jpa annotations moving to jakarta packaging. I provide the solution, including some lines commented out so you can see what was replaced. – Bob Makowski Apr 26 '22 at 17:11
  • I relied on the following [documentation from Spring](https://docs.spring.io/spring-boot/docs/3.0.0-M2/gradle-plugin/reference/htmlsingle/#introduction) – Bob Makowski Apr 26 '22 at 17:18

2 Answers2

1

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.

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
0

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()
}
Bob Makowski
  • 305
  • 2
  • 8
  • also, I had to upgrade java compatibility. in the solution I used '17' for the source and target, and in fact, used the appropriate graalvm for java 17. – Bob Makowski Apr 26 '22 at 17:25