tbroyer / gwt-maven-plugin

Starting fresh on building GWT projects with Maven
https://tbroyer.github.io/gwt-maven-plugin/
Apache License 2.0
167 stars 39 forks source link

Lombok not working with codeserver #142

Closed jiritobias closed 3 years ago

jiritobias commented 3 years ago

I created new project form archetype and added lombok dependency and lombok javaagent to javmArgs (client pom).

mvn archetype:generate \
   -DarchetypeGroupId=net.ltgt.gwt.archetypes \
   -DarchetypeVersion=LATEST \
   -DarchetypeArtifactId=modular-webapp
<dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.14</version>
      <scope>provided</scope>
</dependency>
<jvmArgs>
    <arg>-javaagent:C:\Users\user\.m2\repository\org\projectlombok\lombok\1.18.14\lombok-1.18.14.jar=ECJ</arg>
</jvmArgs>

But when create simple Lombok class in client module like {code} and try make instance of class Test and get value of a new Test().getA(); then client cannot be run (mvn gwt:codeserver -pl modular-app-client -am).

@lombok.Getter
public class Test {
    String a = "lombok.works";
}

It throws error

modular-app/modular-app-client/src/main/java/org/example/App.java:[42,30] cannot find symbol
[ERROR]   symbol:   method getA()
[ERROR]   location: class org.example.App.Test

Adding log with -X parameter. gwt.log

tbroyer commented 3 years ago

The error here comes from the maven-compiler-plugin, which means you didn't setup your build correctly.

  1. the Lombok dependency should go into modular-app-client/pom.xml without the <scope>provided</scope>,
  2. the jvmArgs should go into the root pom.xml next to the sourceLevel and failOnError to apply to all gwt-maven-plugin goals

If I do that, I at least get an error from GWT:

[INFO] --- gwt-maven-plugin:1.0.0:codeserver (default-cli) @ test ---
[INFO] Ignoring test:test-shared:jar:1.0-SNAPSHOT; neither a gwt-lib or jar:sources; Did you forget to use <type>gwt-lib</type> in the dependency declaration?
[INFO] Turning off precompile in incremental mode.
[INFO] Super Dev Mode starting up
[INFO]    workDir: /var/tmp/test/test/target/gwt/codeserver
[WARNING] 2020-10-17 18:46:42.184:INFO::main: Logging initialized @1101ms
[INFO]    Loading Java files in test.App.
[INFO]    Tracing compile failure path for type 'test.App'
[INFO]       [ERROR] Errors in 'file:/var/tmp/test/test/test-client/src/main/java/test/App.java'
[INFO]          [ERROR] Line 42: The method getA() is undefined for the type Test
[INFO]    Tracing compile failure path for type 'test.Test'
[INFO]       [ERROR] Errors in 'file:/var/tmp/test/test/test-client/src/main/java/test/Test.java'
[INFO]          [ERROR] Line 3: lombok cannot be resolved to a type
[INFO]    Finding entry point classes
[INFO]       Tracing compile failure path for type 'test.App'
[INFO]          [ERROR] Errors in 'file:/var/tmp/test/test/test-client/src/main/java/test/App.java'
[INFO]             [ERROR] Line 42: The method getA() is undefined for the type Test
[INFO]       [ERROR] Hint: Check that the type name 'test.App' is really what you meant
[INFO]       [ERROR] Hint: Check that your classpath includes all required source roots

Running with -X I can see the lombok JAR correctly present in the classpath, and the-javaagent correctly passed in:

[DEBUG] Arguments: -javaagent:/home/tbr/.m2/repository/org/projectlombok/lombok/1.18.14/lombok-1.18.14.jar=ECJ com.google.gwt.dev.codeserver.CodeServer -failOnError -workDir /var/tmp/test/test/target/gwt/codeserver -sourceLevel 1.8 -launcherDir /var/tmp/test/test/target/gwt/launcherDir -allowMissingSrc -src /var/tmp/test/test/test-client/src/main/java -src /var/tmp/test/test/test-client/target/generated-sources/annotations -src /var/tmp/test/test/test-shared/src/main/java -src /var/tmp/test/test/test-shared/target/generated-sources/annotations test.App

Interestingly, mvn package works.

That should help you figure out what else is missing. I myself avoid Lombok like the COVID: in my experience, being a hacky way of hacking into compilers, it always causes more problems than it supposedly solves. Either that or try to use delombok instead :man_shrugging:

Anyway, if there's some kind of "incompatibility", it is with GWT itself and not the gwt-maven-plugin (an if it's with GWT, it's IMO a Lombok problem, not a GWT one)

jiritobias commented 3 years ago

@tbroyer thanks, it works. Problem was scope + jvmArgs in client -> it has to be in root pom :)