0

I'm using lombok within IntelliJ. Everything works as expected even when I test the project with maven mvn clean test everything is ok. But when I want to execute test from within IDE I'm getting errors:

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] 

When I add system property -Dlombok.disable=true to run configuration then test executes correctly.
Question is: how can I configure IntelliJ to be able to run JUnit tests from within it or How can I set global property for JUnit tests to disable lombok?

bilak
  • 4,526
  • 3
  • 35
  • 75

3 Answers3

1

You can add any system properties to run configurations within IntelliJ. To have that as a default, you can add the properties to JUnit default configuration in the same dialog (either choose JUnit from the ‘Defaults’ category or press the ‘Edit Defaults’ button).

That’s the answer to your question pertaining the global property. However, fixing the setup for tests to simply run woyld be better. Cannot help there for the moment, however.

Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
1

Have you added Lombok plugin and turned on Annotation Processing (Settings -> Build, Execution, Deployment -> Compiler -> Annotation Processors -> check box "Enable annotation processing")?

Andriy Slobodyanyk
  • 1,965
  • 14
  • 15
0

You need to add the following dependency:

<dependency>
    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    <scope>system</scope>
    <version>1</version>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

See the issue 1058 in Project Lombok and also the the question/answer Compiling a Java Class in memory with `lombok` annotations and Java JDK 8

Michael Piefel
  • 18,660
  • 9
  • 81
  • 112
  • this is what I had before. Unfortunately this is not ok for PMD so I switched from this to another configuration. As I wrote standard maven build is working correctly, I have only problem within IntelliJ – bilak Nov 08 '17 at 06:13
  • Problem is in any case that H2 tries to call a Java compiler for your `ALIAS`, and it does not call it in a way that includes everything. Apart from this failure analysis, I’m afraid I cannot be of further help. – Michael Piefel Nov 08 '17 at 07:56