Vertispan / j2clmavenplugin

Maven plugin to launch new J2CL compilation
https://vertispan.github.io/j2clmavenplugin/
Apache License 2.0
53 stars 26 forks source link

Add integration test for generated code in reactor (JavaCC) #212

Closed zbynek closed 1 year ago

zbynek commented 1 year ago

This integration test fails locally with

[ERROR] annotation-processor-in-reactor:app:1.0/bytecode: /C:/Users/zbynek/git/j2clmavenplugin/j2cl-maven-plugin/target/it-tests/annotation-processor-in-reactor/app/src/main/java/com/example/MyApp.java:7 cannot find symbol
  symbol:   variable BasicParser
  location: class com.example.MyApp
java.lang.RuntimeException: Failed to complete bytecode task, check log
    at com.vertispan.j2cl.build.provided.BytecodeTask.lambda$resolve$3(BytecodeTask.java:100)
    at com.vertispan.j2cl.build.TaskScheduler$2.executeTask(TaskScheduler.java:214)
    at com.vertispan.j2cl.build.TaskScheduler$2.lambda$onReady$0(TaskScheduler.java:266)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
[ERROR] Exception executing task annotation-processor-in-reactor:app:1.0/bytecode
java.lang.RuntimeException: Failed to complete bytecode task, check log
    at com.vertispan.j2cl.build.provided.BytecodeTask.lambda$resolve$3 (BytecodeTask.java:100)
    at com.vertispan.j2cl.build.TaskScheduler$2.executeTask (TaskScheduler.java:214)
    at com.vertispan.j2cl.build.TaskScheduler$2.lambda$onReady$0 (TaskScheduler.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:515)
    at java.util.concurrent.FutureTask.run (FutureTask.java:264)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run (ScheduledThreadPoolExecutor.java:304)
    at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
    at java.lang.Thread.run (Thread.java:829)
java.lang.RuntimeException
    at com.vertispan.j2cl.build.DiskCache.markFailed(DiskCache.java:542)
    at com.vertispan.j2cl.build.DiskCache$CacheResult.markFailure(DiskCache.java:62)
    at com.vertispan.j2cl.build.TaskScheduler$2.executeTask(TaskScheduler.java:235)
    at com.vertispan.j2cl.build.TaskScheduler$2.lambda$onReady$0(TaskScheduler.java:266)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)

If it's my fault please let me know how to fix it, otherwise please check if this can be supported by the J2CL plugin.

niloc132 commented 1 year ago

Please file this as a bug report or discussion next time, though a PR to demonstrate the issue might make sense as well. In this case, you have an extra source directory for the "shared" module (in this case called "resources") that isn't actually declared as needing to be included in the output jar.

Like GWT2, java source files are necessary to be included on the classpath, it isn't enough to include the compiled bytecode. Try adding this to the resources/pom.xml to indicate "my generated sources should be copied to my jar file":

            <resource>
                <directory>target/generated-sources/javacc</directory>
            </resource>

This is not the final fix for your project, as this will still fail to compile, but I hope it becomes more clear now - we know we can't predict all possible project configurations and plugins, so we try to be consistent with how we handle artifacts and other reactor projects. A later problem you may note is that j2cl:watch does not re-run the entire mvn compile after each change (afaict that isn't generally even possible, much less if you also need to apply j2cl's GwtIncompatibleStripper...), so you'll need to run that command directly to regenerate those types, and j2cl should notice that change.

Here's the next error I encountered:

[INFO] Starting annotation-processor-in-reactor:app:1.0-test/transpiled_js
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:6: The import java.io.BufferedReader cannot be resolved
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:9: The import java.io.InputStreamReader cannot be resolved
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:24: BufferedReader cannot be resolved to a type
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:24: InputStreamReader cannot be resolved to a type
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:28: BufferedReader cannot be resolved to a type
[ERROR] annotation-processor-in-reactor:resources:1.0/transpiled_js: Error:StreamProvider.java:28: InputStreamReader cannot be resolved to a type
[ERROR] Exception executing task annotation-processor-in-reactor:resources:1.0/transpiled_js

GWT/J2CL's emul doesn't include these types/members, so you'll have to add them, or modify the javacc output to not need them.

Please reply if you have more questions/thoughts, but I think we should move to an issue/discussion.