我在IntelliJ中使用lombok。即使我用maven mvn clean test
测试项目一切正常,一切都按预期工作。但是当我想在IDE中执行测试时,我遇到了错误:
org.springframework.jdbc.datasource.init.ScriptStatementFailedException: Failed to execute SQL script statement #3 of class path resource [sql/core-base-schema.sql]: CREATE ALIAS GETTEXT AS'
String getText(Long textId, String langId) {
return "testText";
}'; nested exception is org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement "/org/h2/dynamic/GETTEXT.java:5: warning: Can't initialize javac processor due to (most likely) a class loader problem: java.lang.NoClassDefFoundError: com/sun/tools/javac/processing/JavacProcessingEnvironment
public class GETTEXT {
^
at lombok.javac.apt.LombokProcessor.init(LombokProcessor.java:83)
at lombok.core.AnnotationProcessor$JavacDescriptor.want(AnnotationProcessor.java:87)
at lombok.core.AnnotationProcessor.init(AnnotationProcessor.java:140)
at lombok.launch.AnnotationProcessorHider$AnnotationProcessor.init(AnnotationProcessor.java:69)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$ProcessorState.<init>(JavacProcessingEnvironment.java:500)
...
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.processing.JavacProcessingEnvironment
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at lombok.launch.ShadowClassLoader.loadClass(ShadowClassLoader.java:422)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 55 more
1 warning
"; SQL statement:
CREATE ALIAS GETTEXT AS'
String getText(Long textId, String langId) {
return "testText";
}' [42000-191]
当我添加系统属性-Dlombok.disable=true
以运行配置时,测试会正确执行
问题是:如何配置IntelliJ以便能够从其中运行JUnit测试或如何为JUnit测试设置全局属性以禁用lombok?
答案 0 :(得分:1)
您可以添加任何系统属性以在IntelliJ中运行配置。要将其作为默认值,您可以在同一对话框中将属性添加到JUnit默认配置(从“默认值”类别中选择JUnit或按“编辑默认值”按钮)。
这是关于全球财产问题的答案。但是,修复测试设置以简单地运行woyld会更好。但是,暂时无法帮助那里。
答案 1 :(得分:1)
您是否添加了Lombok插件并启用了注释处理(设置 - &gt;构建,执行,部署 - &gt;编译器 - &gt;注释处理器 - &gt;复选框“启用注释处理”)?
答案 2 :(得分:0)
您需要添加以下依赖项:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<scope>system</scope>
<version>1</version>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
请参阅issue 1058 in Project Lombok以及问题/答案Compiling a Java Class in memory with `lombok` annotations and Java JDK 8