Hi, I’m struggling to find the way to make Groovy incremental compilation work when I use annotation processors in Java.
I’ve created a dummy project where I use 3 source sets: main, test and componentTest. In main, I have a single Java class annotated with Lombok. In test, I have a single Groovy test class that instantiates the class written in Java.
I’ve setup this dummy project so that I can find a fix for a bigger one where I’m facing the same issue.
When I enable Groovy incremental compilation and build the project, I get an error that says:
Enabling incremental compilation and configuring Java annotation processors for Groovy compilation is not allowed. Disable incremental Groovy compilation or remove the Java annotation processor configuration.
This is expected since a change made to Gradle last year: Disable incremental Groovy compilation when Java annotation processors are present · Issue #9871 · gradle/gradle · GitHub
I’d like to know whether it’s possible to enable Groovy incremental compilation somehow if I use any annotation processor in a different source set in Java.
Versions:
Gradle: 6.6.1
Lombok: 1.18.16 (through io.freefair.lombok plugin 5.3.0)
Groovy: 3.0.7
Java: 11
build.gradle
plugins {
id 'org.springframework.boot' version '2.4.0'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
id 'groovy'
id "io.freefair.lombok" version "5.3.0"
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
configurations {
componentTestImplementation.extendsFrom testImplementation
}
tasks.withType(GroovyCompile).configureEach {
options.incremental = true
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.spockframework:spock-spring:2.0-M4-groovy-3.0'
implementation group: 'org.codehaus.groovy', name: 'groovy', version: '3.0.7'
componentTestImplementation 'org.springframework.boot:spring-boot-starter-test'
componentTestImplementation 'io.cucumber:cucumber-spring:6.9.0'
componentTestImplementation platform('org.testcontainers:testcontainers-bom:1.15.0') //import bom
componentTestImplementation('org.testcontainers:postgresql') //no vers
}
sourceSets {
componentTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/componentTest/java')
}
resources.srcDir file('src/componentTest/resources')
}
}
task componentTest(type: Test) {
testClassesDirs = sourceSets.componentTest.output.classesDirs
classpath = sourceSets.componentTest.runtimeClasspath
}
check.dependsOn componentTest
componentTest.mustRunAfter test
test {
useJUnitPlatform()
}
componentTest {
useJUnitPlatform()
}
settings.gradle
rootProject.name = 'tdd-playground'
enableFeaturePreview('GROOVY_COMPILATION_AVOIDANCE')
Account.java
package com.example.tddplayground;
import lombok.Value;
import java.math.BigDecimal;
@Value
public class Account {
String name;
BigDecimal amount;
}
AccountTest.groovy
package com.example.tddplayground
import spock.lang.Specification
class AccountTest extends Specification {
def "test"() {
when:
def accountId = new Account("Main account", BigDecimal.ZERO)
then:
accountId.name == "Main account"
accountId.amount == BigDecimal.ZERO
}
}
@Stefan_Wolf posting the question here since I believe it’s more appropriate.
I don’t understand what I need to do when you say:
@albloptor I the Lombok annotation processor configured for the Groovy compilation as well? If it isn’t (and it shouldn’t be), then I think incremental Groovy compilation should work if you enabled it.
Thanks in advance!