首页 > 解决方案 > Lombok 安装程序不适用于带有 Gradle 项目的 Eclipse

问题描述

我有一个使用 Lombok 进行注释的 Eclipse 项目。一个这样的注释是@Access。即使我明确地将 lombok.jar 放在项目的类路径中,Eclipse 编译器也看不到这一点。我希望我可以让 Eclipse 插件工作,但会满足于修改构建脚本而不是将它们签入。

Lombok jar 版本 1.18.22 Eclipse(试用了最新的 MyEclipse 和 2021-09)。在 Linux 上运行

根据项目说明,我跑了

java -jar lombok.jar

并指定我的 Eclipse 目录。

它将 lombok.jar 复制到 Eclipse 目录并将 eclipse.ini 文件修改为:

-startup
plugins/org.eclipse.equinox.launcher_1.6.300.v20210813-1054.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.2.300.v20210828-0802
-product
org.eclipse.epp.package.jee.product
-showsplash
org.eclipse.epp.package.common
--launcher.defaultAction
openFile
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vm
plugins/org.eclipse.justj.openjdk.hotspot.jre.full.linux.x86_64_16.0.2.v20210721-1149/jre/bin
-vmargs
-Dosgi.requiredJavaVersion=11
-Dosgi.instance.area.default=@user.home/eclipse-workspace
-Dsun.java.command=Eclipse
-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM
-Dosgi.requiredJavaVersion=11
-Dosgi.dataAreaRequiresExplicitInit=true
-Dorg.eclipse.swt.graphics.Resource.reportNonDisposed=true
-Xms256m
-Xmx2048m
--add-modules=ALL-SYSTEM
-javaagent:lombok.jar

但是注释处理仍然不起作用。我在 Gradle 商店,但我不确定在哪里放置插件修改或非插件 gradle 修改。我尝试添加

compileOnly 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'

直接到依赖关系,但它并不关心。

我的 Gradle 文件看起来与指定的示例不同。我的 build.gradle 是:

import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.JavaVersion

apply plugin: "distribution"
apply plugin: "idea"
apply plugin: "io.spring.dependency-management"
apply plugin: "jacoco"
apply plugin: "java"
apply plugin: "maven"
apply plugin: "org.liquibase.gradle"
apply plugin: "org.springframework.boot"
// apply plugin: "org.unbroken-dome.test-sets"

def javaVersion = JavaVersion.VERSION_11;
sourceCompatibility = javaVersion;
targetCompatibility = javaVersion; // defaults to sourceCompatibility

bootRun {
    systemProperties = System.properties
    systemProperty 'management.info.git.mode', 'FULL'
}

ext {
    groupId = project.property('groupId')
    version = project.property('version')
    fernCommonVersion = project.property('fernCommonVersion')
    walnutCommonVersion = project.property('walnutCommonVersion')
}

group groupId
version version

buildscript {
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        // classpath group: "gradle.plugin.org.unbroken-dome.gradle-plugins", name: "gradle-testsets-plugin", version: "1.4.2"
        classpath group: "io.spring.gradle", name: "dependency-management-plugin", version: "1.0.10.RELEASE"
        classpath group: "org.codehaus.groovy", name: "groovy-all", version: "2.0.1"
        classpath group: "org.codehaus.groovy", name: "groovy-xml", version: "2.0.1"
        classpath group: "org.liquibase", name: "liquibase-gradle-plugin", version: "2.0.1"
        classpath group: "org.postgresql", name: "postgresql", version: "42.2.0"
        classpath group: "org.springframework.boot", name: "spring-boot-gradle-plugin", version: "2.3.4.RELEASE"
        classpath group: "pl.project13.maven", name: "git-commit-id-plugin", version: "2.2.1"
    }
}

jacoco {
    toolVersion = "0.8.5"
    reportsDir = file("$buildDir/reports/jacoco")
}

jacocoTestReport {
    reports {
        xml.enabled true
        csv.enabled false
        xml.destination file("${buildDir}/reports/jacoco/coverage.xml")
        html.destination file("${buildDir}/reports/jacoco/html")
    }
}

springBoot {
    mainClassName = 'com.tii.walnut.manager.AcornManagerApplication'
    buildInfo {
        // Generate extra build info.
        properties {
            additional = [
                    by             : System.properties['user.name'],
                    operatingSystem: "${System.properties['os.name']} (${System.properties['os.version']})",
                    // machine: InetAddress.localHost.hostName,
                    // Override buildInfo property time
                    time           : buildTime()
            ]
        }
    }

}

def buildTime() {
    final dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ")
    dateFormat.timeZone = java.util.TimeZone.getTimeZone('GMT')
    dateFormat.format(new Date())
}

repositories {
    mavenLocal()
    maven { url 'http://bin-repo.iparadigms.com/artifactory/libs-release' }
    maven { url 'http://bin-repo.iparadigms.com/artifactory/libs-snapshot' }
    mavenCentral()
    maven { url "http://repo.spring.io/release" }
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven { url "https://jitpack.io" }
    maven { url "http://dl.bintray.com/typesafe/maven-releases" }
    maven { url "https://repository.apache.org/snapshots" }
}

sourceSets {
    main {
        java.srcDir 'src/main/java'
    }
    test {
        java.srcDir 'src/test/java'
        resources.srcDir 'src/test/resources'
    }
}

configurations {
    codacy
    // we use the tii commons logging module for logging
    compile.exclude module: 'log4j12'
    compile.exclude module: 'slf4j-log4j12'
    compile.exclude module: 'log4j-slf4j-impl'
    compile.exclude module: 'log4j-core'
    compile.exclude module: 'log4j-api'
    compile.exclude module: 'spring-boot-starter-tomcat'
    compile.exclude module: 'log4j-over-slf4'
}

dependencies {
    compile (group: "com.tii", name: "fern-common", version: "${fernCommonVersion}") {
          exclude group: "org.springframework.boot"
          exclude group: "org.slf4j"
          exclude module: 'spring-boot-starter-jetty'
    }
    compile group: "com.tii.walnut", name: "walnut-common", version: "${walnutCommonVersion}"
    compile (group: 'com.turnitin.commons', name: 'logging', version: '0.0.2') {
         exclude group: "org.springframework.boot"
    }
    compile (group: 'com.turnitin.commons', name: 'stream', version: '1.2-SNAPSHOT') {
         // sadly the common libraries have incorrectly defined dependencies on Spring - this leads to version mismatches
         exclude group: "org.springframework.boot"
         exclude group: "org.springframework"
    }
    compile group: 'com.turnitin.commons', name: 'metrics', version: '0.3.8'

    compile group: "com.fasterxml.jackson.dataformat", name: "jackson-dataformat-yaml"

    compile group: "com.google.guava", name: "guava", version: "23.0"
    compile group: 'com.jayway.jsonpath', name: 'json-path', version: '2.5.0'
    compile group: "com.newrelic.agent.java", name: "newrelic-api", version: "4.1.0"
    compile group: 'com.opencsv', name: 'opencsv', version: '5.5.1'

    compile group: "com.squareup.okhttp3", name: "okhttp", version: "3.6.0"

    compile group: "com.vladmihalcea", name: "hibernate-types-52", version: "2.9.11"

    compile group: "io.jsonwebtoken", name: "jjwt", version: "0.7.0"

    compile group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'

    compile group: "net.jodah", name: "failsafe", version: "2.4.0"

    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
    compile group: "org.apache.commons", name: "commons-lang3", version: "3.9"
    compile group: "org.aspectj", name: "aspectjweaver", version: "1.8.8"

    compile (group: "org.codehaus.janino", name: "commons-compiler", version: "3.0.8") {
        force = true
        exclude group: "org.codehaus.janino", module: "janino"
    }
    compile group: "org.codehaus.janino", name: "janino", version: "3.0.8"

    compile group: "org.functionaljava", name: "functionaljava-java8", version: "4.7"

    compile group: "org.hibernate", name: "hibernate-c3p0", version: "5.2.10.Final"
    compile group: "org.hibernate", name: "hibernate-java8", version: "5.2.10.Final"

    compile group: "org.postgresql", name: "postgresql", version: "42.2.1"

    compile group: "org.springframework", name: "spring-context-support"
    compile group: "org.springframework.boot", name: "spring-boot-starter"
    compile group: "org.springframework.boot", name: "spring-boot-starter-actuator"
    compile group: "org.springframework.boot", name: "spring-boot-starter-data-jpa"
    compile group: "org.springframework.boot", name: "spring-boot-starter-jdbc"
    compile group: "org.springframework.boot", name: "spring-boot-starter-web"
    compile group: "org.springframework.boot", name: "spring-boot-starter-webflux"
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
    compile group: 'org.springframework.plugin', name: 'spring-plugin-core'
    compile group: 'com.turnitin.commons', name: 'launchdarkly', version: '0.0.13'

    runtime group: "org.springframework.boot", name: "spring-boot-devtools"
    runtime("ch.qos.logback:logback-core") 

    testCompile group: "org.apiguardian", name: "apiguardian-api", version: "1.0.0"
    testCompile group: "org.awaitility", name: "awaitility", version: "3.0.0"
    testCompile group: "org.junit.jupiter", name: "junit-jupiter-api", version: "5.3.2"
    testCompile group: "org.junit.jupiter", name: "junit-jupiter-params", version: "5.3.2"
    testCompile group: "org.liquibase", name: "liquibase-core", version: "3.6.3"
    testCompile group: "org.lz4", name: "lz4-java", version: "1.4.1"
    testCompile group: 'org.mockito', name: 'mockito-core', version: '2.28.2'
    testCompile group: "org.springframework", name: "spring-test"
    testCompile group: "org.springframework.boot", name: "spring-boot-starter-test"

    liquibaseRuntime group: "ch.qos.logback", name: "logback-classic", version: "1.2.3"
    liquibaseRuntime group: "ch.qos.logback", name: "logback-core", version: "1.2.3"
    liquibaseRuntime group: "org.liquibase", name: "liquibase-core", version: "3.6.3"
    liquibaseRuntime group: "org.postgresql", name: "postgresql", version: "42.2.1"
    liquibaseRuntime group: "org.slf4j", name: "slf4j-api", version: "1.7.25"

    testRuntime group: "org.junit.jupiter", name: "junit-jupiter-engine", version: "5.3.2" 

    codacy group: "com.github.codacy", name: "codacy-coverage-reporter", version: "-SNAPSHOT"
}

ext.testsRegEx = project.hasProperty('tests') ? project.getProperty('tests') : "*"

test {
    jacoco {
        append = false
        destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
        classDumpDir = file("$buildDir/jacoco/classpathdumps")
    }

    useJUnitPlatform {
        excludeTags 'slow'
    }

    filter {
        includeTestsMatching "${testsRegEx}"
    }

    minHeapSize = "4g"
    maxHeapSize = "8g"

    reports.junitXml.destination = file('build/test-results/junit-platform')

    testLogging {
        exceptionFormat = 'full'
        events = ["passed", "skipped", "failed"]
    }

    if (System.getProperty('DEBUG', 'false') == 'true') {
        jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9099'
    }
}

liquibase {
    activities {
        // new Dev env
        uscald {
            changeLogFile 'src/main/resources/database/Changelog.xml'
            url 'jdbc:postgresql://dev-walnut-leader.uscald:5432/walnut?currentSchema=manager'
            username 'walnut_admin'
            password 'somepasswd'
            liquibaseSchemaName 'public'
        }
    }
    runList = 'uscald'
}

install.dependsOn(bootJar)
distributions {
    main {
        contents {
            from jar
        }
    }
}

// this for debugging remotely - add -DDEBUG=true  to the command line - remote debug at 9099
tasks.withType(JavaExec) {
    if (System.getProperty('DEBUG', 'false') == 'true') {
        jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9099'
    }
}

// generated from bootstrap-jet - begin
task resolveDependencies {
    doLast {
        project.rootProject.allprojects.each { subProject ->
            subProject.buildscript.configurations.each { configuration ->
                resolveConfiguration(configuration)
            }
            subProject.configurations.each { configuration ->
                resolveConfiguration(configuration)
            }
        }
    }
}

void resolveConfiguration(configuration) {
    if (isResolveableConfiguration(configuration)) {
        configuration.resolve()
    }
}

boolean isResolveableConfiguration(configuration) {
    def nonResolveableConfigurations = ['apiElements', 'implementation',
                                        'runtimeElements', 'runtimeOnly',
                                        'testImplementation', 'testRuntimeOnly',
                                        'generatedImplementation', 'generatedRuntimeOnly']

    if (nonResolveableConfigurations.contains(configuration.getName())) {
        return false
    }
    return true
}
// generated from bootstrap-jet - end

标签: eclipsegradlelombok

解决方案


推荐阅读