Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow for a non-local Java Compiler to be used #1988

Merged
merged 2 commits into from
Aug 12, 2022

Commits on Aug 12, 2022

  1. feat: allow for a non-local Java Compiler to be used

    Currently if you want to pass in some `javacOptions` that start with
    `-J` the Java compiler will reject them since the local java compiler
    won't accept `-J` flags. You can see this in an example on JDK 17 where
    you need some `-J` flags to get the java semantidb compiler plugin to
    work:
    
    ```scala
    object javaModule extends JavaModule {
    
      def ivyDeps = Agg(ivy"com.sourcegraph:semanticdb-javac:0.8.2")
    
      def javacOptions = Seq(
        "-J--add-exports",
        "-Jjdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
        "-J--add-exports",
        "-Jjdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
        "-J--add-exports",
        "-Jjdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED",
        "-J--add-exports",
        "-Jjdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
        "-J--add-exports",
        "-Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
        s"-Xplugin:semanticdb -sourceroot:${T.workspace} -targetroot:${T.dest}"
      )
    
    }
    ```
    
    Which will result in:
    
    ```
    ❯ mill javaModule.compile
    [19/19] javaModule.compile
    [info] compiling 1 Java source to /Users/ckipp/Documents/scala-workspace/minimal/out/javaModule/compile.dest/classes ...
    [warn] Javac is running in 'local' mode. These flags have been removed:
    [warn]  -J--add-exports, -Jjdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED, -J--add-exports, -Jjdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED, -J--add-exports, -Jjdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED, -J--add-exports, -Jjdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED, -J--add-exports, -Jjdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
    [error] An exception has occurred in the compiler (17.0.4). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
    [error] java.lang.IllegalAccessError: class com.sourcegraph.semanticdb_javac.SemanticdbPlugin (in unnamed module @0x4e59433c) cannot access class com.sun.tools.javac.api.BasicJavacTask (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @0x4e59433c
    ...
    ```
    
    This change looks at the `javacOptions` when creating the java comipler
    and if detected makes sure you get a non-local compiler. If none are
    detected, then the behavior basically is the same as it was before where
    a local instance is used.
    
    We also cache this to ensure it's not created over and over. However if
    your `javacOption` change, then we do give a new instance.
    
    Fixes com-lihaoyi#1983
    ckipp01 committed Aug 12, 2022
    Configuration menu
    Copy the full SHA
    b997457 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7df6ead View commit details
    Browse the repository at this point in the history