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


Solution 1:[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.

Solution 2:[2]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy Wilkinson
Solution 2 Bob Makowski