我有一个 Eclipse 项目,它使用 Lombok 进行注释。 @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
[email protected]/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
我正在开发 Spring Boot 应用程序,并在 Eclipse 中遇到了 Lombok 的问题。 以下是正确设置的方法:
java -jar lombok.jar 出现提示时,指定 Eclipse 安装目录的路径,而不是工作区的路径。例如:C:\Program Files Clipse
更新build.gradle: 将 Lombok 依赖项添加到您的 build.gradle 文件中,如下所示:
依赖项{ 仅编译 'org.projectlombok:lombok:1.18.34' 注释处理器'org.projectlombok:lombok:1.18.34'
testCompileOnly 'org.projectlombok:lombok:1.18.34'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.34'
}
重新启动 Eclipse: 更新 build.gradle 文件后,重新启动 Eclipse IDE 以确保 Lombok 插件正确加载和识别。