Humank
Humank

Reputation: 23

Gradle multiple project gradle build fail with lombok 1.8.10 but compile well

I'm developing a gradle-multiple-project java application, code works well with lombok in intellij (getter, setter method is visible), but when I run gradle build then fail, get the message:

~/EventStormingWorkShop/sources/coffeeshop/coffee-domain/src/main/java/solid/humank/port/adapter/OrderReceiverAdapter.java:41: error: cannot find symbol
            String orderString= mapper.writeValueAsString(orderCreatedEvent.getDetail());
                                                                           ^
  symbol:   method getDetail()
  location: variable orderCreatedEvent of type OrderCreatedEvent

Current environment: Intellij : 2019.2.3 Gradle : 5.6.2 JDK : GraalVM 19.2.0 (compatible with JDK 1.8_0222) lombok : 1.8.10

I had checked the lombok dependencies declaration in build.gradle.

compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"

at compile time everything wen well.

Here is the build.gradle from my rootProject

buildscript {
    ext {
        quarkusJunitVersion = '0.22.0'
        restAssuredVersion = '3.3.0'
        cucumberVersion = '4.7.1'
        lombokVersion = '1.18.10'
        quarkusVersion = '0.23.1'
        awsJavaVersion = '1.11.631'
        awsVersion = '2.5.29'
    }

}

apply from: file("${rootDir}/gradle/project.gradle")

List testCompilePackage = ["io.quarkus:quarkus-junit5:${quarkusJunitVersion}", "io.rest-assured:rest-assured:${restAssuredVersion}"]
List testImplementPackage = ["io.cucumber:cucumber-java8:${cucumberVersion}", "io.cucumber:cucumber-junit:${cucumberVersion}"]
List implementationPackage = ["io.quarkus:quarkus-resteasy",
                              "com.amazonaws:aws-java-sdk-lambda",
                              "com.amazonaws:aws-java-sdk-dynamodb",
                              "com.amazonaws:aws-lambda-java-core",
                              "com.amazonaws:aws-lambda-java-events",
                              "com.amazonaws:aws-java-sdk-events"]


subprojects { dir ->
    repositories {
        mavenCentral()
    }

    dependencies {
        // Lombok Support
        compileOnly "org.projectlombok:lombok:${lombokVersion}"
        annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
        testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
        testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
        // quarkus test
        testCompile testCompilePackage
        // cucumber test
        testImplementation testImplementPackage
        // quarkus
        compile group: 'io.quarkus', name: 'quarkus-gradle-plugin', version: "${quarkusVersion}", ext: 'pom'
        implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}")
        implementation platform("com.amazonaws:aws-java-sdk-bom:${awsJavaVersion}")
        implementation platform("software.amazon.awssdk:bom:${awsVersion}")
        implementation implementationPackage
    }


    if (dir.name.endsWith("-domain")) {
        dependencies {
            implementation project(":ddd-commons")
        }
    }

    if (dir.name.endsWith("-application")) {
        String modName = dir.name.substring(0, dir.name.lastIndexOf("-application"))
        dependencies {
            implementation project(":ddd-commons"), project(":${modName}-domain")
        }
    }

    if (dir.name.endsWith("-web")) {
        String modName = dir.name.substring(0, dir.name.lastIndexOf("-web"))
        dependencies {
            implementation project(":ddd-commons"), project(":${modName}-domain"), project(":${modName}-application")
        }
    }
}

The build.gradle will apply a project.gradle file

project.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'io.quarkus:quarkus-gradle-plugin:0.23.1'
    }
}

defaultTasks 'clean', 'build'

apply plugin: 'idea'

subprojects {
    apply plugin: 'java'
    apply plugin: io.quarkus.gradle.QuarkusPlugin

    group 'solid.humank.coffeeshop'
    version '1.0'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    idea.module.inheritOutputDirs = true

    dependencies{
        compileOnly "org.projectlombok:lombok:1.18.10"
        annotationProcessor "org.projectlombok:lombok:1.18.10"
        testCompileOnly "org.projectlombok:lombok:1.18.10"
        testAnnotationProcessor "org.projectlombok:lombok:1.18.10"
    }

    tasks.withType(JavaCompile).configureEach {
        options.encoding = 'UTF-8'
        options.deprecation = true
        options.compilerArgs += ['-Xlint:none', '-proc:none', '-nowarn']
    }

    repositories {
        mavenCentral()
        mavenLocal()
    }

    buildDir = "${rootDir}/build/${rootDir.relativePath(projectDir)}"

    tasks.named('test') {
        useJUnitPlatform()
        failFast = true
        testLogging.showStandardStreams = true
        testLogging.exceptionFormat 'full'
    }

    tasks.named('jar') {
        // put parent name in final jar name, to resolve collision of child projects with same name under different parents
        if (parent.depth > 0) {
            archiveBaseName = "${parent.name}-${archiveBaseName.get()}"
        }
    }

    afterEvaluate {
        def buildTime = new Date()
        tasks.withType(Jar) {
            String ClassPathString = ''
            configurations.runtime.each { ClassPathString += " lib\\" + it.name }
            manifest {
                attributes 'Implementation-Title': project.name,
                        'Implementation-Version': project.version,
                        'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')})",
                        'Built-With': "gradle-${project.gradle.gradleVersion}, groovy-${GroovySystem.version}",
                        'Built-By': System.getProperty('user.name'),
                        'Built-On': "${InetAddress.localHost.hostName}/${InetAddress.localHost.hostAddress}",
                        'Build-Time': buildTime.format('yyyy/MM/dd HH:mm:ss'),
                        'Class-Path': ClassPathString
            }
        }
    }
}

Besides, there is the settings.gradle to include sub projects

pluginManagement {
    repositories {
        mavenCentral()
        gradlePluginPortal()
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'io.quarkus') {
                useModule("io.quarkus:quarkus-gradle-plugin:0.23.1")
            }
        }
    }
}
rootProject.name = 'coffeeshop'
include 'ddd-commons'

include 'inventory-domain'
include 'inventory-application'
include 'inventory-web'
include 'coffee-application'
include 'coffee-domain'
include 'coffee-web'
include 'orders-application'
include 'orders-domain'
include 'orders-web'

I expect these settings could run gradle build well, but faced seems lombok annotation processer not worked issue in gradle runtime.

Upvotes: 0

Views: 1591

Answers (1)

koji lin
koji lin

Reputation: 677

Because your project.gradle has '-proc:none'

Upvotes: 1

Related Questions