将Lombok添加到Intellij中的Gradle项目中



Gradle新手。如果这是一个糟糕的问题,我深表歉意。

我一直在尝试启动一个简单的Java8Gradle项目。一切都很好,直到我尝试将龙目添加到我的项目中。

我的Intellij IDE具有Lombok所需的所有设置。

  1. Lombok插件已安装并激活
  2. 注释处理器已打开

IDE完美地处理了注释。没有显示错误,并且样板显示在代码结构中。

然而,当我尝试使用Intellij构建项目或运行主方法时,编译器会抱怨Lombok应该生成的样板文件不存在。

环境

186590cf4989:JokerJava$ gradlew --version
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.5 (Oracle Corporation 11.0.5+10-LTS)
OS:           Mac OS X 10.14.6 x86_64

下面的一些错误消息:

8:23:21 PM: Executing task 'build'...
> Task :generateLombokConfig UP-TO-DATE
> Task :compileJava FAILED
2 actionable tasks: 1 executed, 1 up-to-date
warning: You aren't using a compiler supported by lombok, so lombok will not work and has been disabled.
Your processor is: org.gradle.api.internal.tasks.compile.processing.IncrementalProcessingEnvironment
Lombok supports: sun/apple javac 1.6, ECJ
workspace/tank/JokerJava/src/main/java/tictactoe/game/gui/TicTacToeButton.java:11: error: variable index not initialized in the default constructor
private final int index;
^
workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:42: error: constructor TicTacToeButton in class TicTacToeButton cannot be applied to given types;
buttons[i] = new TicTacToeButton(i);
^
required: no arguments
found: int
reason: actual and formal argument lists differ in length
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:70: error: cannot find symbol
int index = buttonClicked.getIndex();
^
symbol:   method getIndex()
location: variable buttonClicked of type TicTacToeButton
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol:   method getPlayer()
location: variable opponentAction of type UserAction
/workspace/tank/JokerJava/src/main/java/tictactoe/game/TicTacToe.java:86: error: cannot find symbol
update(opponentAction.getPlayer(), opponentAction.getIndex());
^
symbol:   method getIndex()
location: variable opponentAction of type UserAction
Note: /workspace/tank/JokerJava/src/main/java/Client.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
5 errors
1 warning
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
8:23:22 PM: Task execution finished 'build'.

请参阅下面的构建.gradle配置

plugins {
id 'java'
id "io.freefair.lombok" version "5.0.0-rc2"
}
group 'org.example'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}

即使您不想使用spring,也可以在https://start.spring.io/并选择Gradle并添加Lombok依赖项。它将在适当的配置(包括annotationProcessor(中使用Lombok为您创建一个build.gradle

最新更新