VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
550 stars 129 forks source link

Annotation processing warning while running Java code #3005

Open yadavan88 opened 4 months ago

yadavan88 commented 4 months ago

Version(s) 1.4.0

Describe the bug When running a Java class using scala-cli, it shows this warning.

Annotation processing is enabled because one or more processors were found
  on the class path. A future release of javac may disable annotation processing
  unless at least one processor is specified by name (-processor), or a search
  path is specified (--processor-path, --processor-module-path), or annotation
  processing is enabled explicitly (-proc:only, -proc:full).
  Use -Xlint:-options to suppress this message.
  Use -proc:none to disable annotation processing.
Warning: Error reading API from class file: JavaArgs : java.lang.UnsupportedClassVersionError: Preview features are not enabled for JavaArgs (class file version 65.65535). Try running with '--enable-preview'

To Reproduce

Expected behaviour No warning

Metals Log:

2024.07.05 18:53:33 INFO  Correctly reloaded workspace
2024.07.05 18:53:35 INFO  time: indexed workspace in 2.25s
Jul 05, 2024 6:54:07 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 69
2024.07.05 18:54:13 WARN  no build tool detected in workspace '/Users/yadukrishnan/scala-cli/java-args'. The most common cause for this problem is that the editor was opened in the wrong working directory, for example if you use sbt then the workspace directory should contain build.sbt. 
2024.07.05 18:54:18 INFO  compiling java-args_878aa6f544 (1 java source)
2024.07.05 18:54:20 INFO  Note: /Users/yadukrishnan/scala-cli/java-args/JavaArgs.java uses preview features of Java SE 21.
2024.07.05 18:54:20 INFO  Note: Recompile with -Xlint:preview for details.
2024.07.05 18:54:20 WARN  Error reading API from class file: JavaArgs : java.lang.UnsupportedClassVersionError: Preview features are not enabled for JavaArgs (class file version 65.65535). Try running with '--enable-preview'
2024.07.05 18:54:20 INFO  time: compiled java-args_878aa6f544 in 1.91s
Jul 05, 2024 6:57:51 PM org.eclipse.lsp4j.jsonrpc.RemoteEndpoint handleCancellation
WARNING: Unmatched cancel notification for request id 95
Gedochao commented 3 months ago

interesting... so it seems this warning is printed somewhere in Bloop, maybe? it goes away when using --server=false:

scala-cli JavaArgs.java --server=false
# Note: ~/IdeaProjects/scala-cli-tests-2/untitled/cli-java-repro/JavaArgs.java uses preview features of Java SE 21.
# Note: Recompile with -Xlint:preview for details.
# appName = baeldungApp , language = english and country = usa
Gedochao commented 3 months ago

It seems we should explicitly enable annotation processing in some cases, so that the Java compiler is satisfied... Still not sure where we introduce a processor, however.

Gedochao commented 3 months ago

Likely guess: this may be caused by us using the SemanticDB compiler plugin. it seems we should explicitly enable annotation processing on JDKs 21+, and possibly pass the processor path to the Java compiler. Some more investigation may be required.