使用Lombok 1.8.10分级多项目gradle构建失败,但编译良好

问题描述 投票:0回答:1

我正在开发一个gradle-multi-project Java应用程序,代码与intellij中的lombok配合良好(getter,setter方法可见),但是当我运行gradle build然后失败时,得到消息:

~/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

当前环境:Intellij:2019.2.3摇篮:5.6.2JDK:GraalVM 19.2.0(与JDK 1.8_0222兼容)龙目岛:1.8.10

我检查了build.gradle中的lombok依赖项声明。

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

在编译时一切顺利。

这是我的rootProject中的build.gradle

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

build.gradle将应用project.gradle文件

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

此外,还有settings.gradle包含子项目

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'

我希望这些设置可以很好地运行gradle构建,但是在gradle运行时似乎遇到了lombok批注处理程序无法正常工作的问题。

gradle intellij-idea java-8 lombok
1个回答
0
投票

因为您的project.gradle具有'-proc:none'

© www.soinside.com 2019 - 2024. All rights reserved.