我正在研究libGDX项目,我想使用Lombok。我遵循this short tutorial的有关在libGDX项目中使用lombok的信息,但不幸的是它无法正常工作。
情况看起来像这样-IntelliJ正在识别lombok,并且没有抱怨get / set方法,但是当我想运行项目(使用gradle)时,会出现
这样的Java编译器错误错误:找不到符号静态生成器
错误:找不到符号方法setBoardSize(float a,float b)
因此基本上不认识龙目岛。
通常,建议是在IntelliJ中设置“ 启用批注处理”,但我尝试失败了-我还尝试重新安装Lombok插件,将Lombok版本更改为1.18.8,然后添加到build.gradle android部分
annotationProcessor“ org.projectlombok:lombok:1.16.6”
,但没有任何解决此问题的方法。我还相信这不是IntelliJ的问题,因为当我尝试使用gradle命令行运行项目时
gradlew桌面:运行
它不起作用,并且我具有相同的堆栈跟踪
有人有同样的问题吗?该如何解决?
我将 build.gradle 附加在下面
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.6'
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = "light-game"
gdxVersion = '1.9.8'
roboVMVersion = '2.3.3'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.8.0'
}
repositories {
mavenLocal()
mavenCentral()
google()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
providedCompile "org.projectlombok:lombok:1.16.6"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
provided "org.projectlombok:lombok:1.16.6"
}
}
project(":core") {
apply plugin: "java"
apply plugin: "war"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
providedCompile "org.projectlombok:lombok:1.16.6"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion:sources"
}
}
tasks.eclipse.doLast {
delete ".project"
}
答案 0 :(得分:0)
哦-终于我找到了问题,这非常令人惊讶。原来我的配置很好,IntelliJ很好,但是Lombok本身有一个我不知道的问题-这个问题是 builder()方法的静态导入,它完全弄乱了已编译的字节码类并导致类似我的问题
基本上我要做的就是删除诸如这样的进口
import static com.antkowicz.project.MyClass.builder;
public MyClass getMyClass() {
return builder().build();
}
,而不是使用
import static com.antkowicz.project.MyClass;
public MyClass getMyClass() {
return MyClass.builder().build();
}
似乎这个问题是众所周知的,但不会很快(或永远不会)得到解决,这并不是什么小事-因此,基本上,我们唯一能做的就是用Lombok省略静态导入(至少是 builder() ):)
下面有关该主题的一些链接: