Commit 2b14b77
committed
Fix javac plugin compilation under JDK 17+
JavaToolchainPlugin (now removed) used to mask three JDK-17+ issues in
the javacPlugin project by pinning its compile JDK to 11, stripping flags
from the doc task, and forcing --release 11 on all Java code. With the
plugin gone, all three surface:
1. JDK 14 added Plugin.autoStart(), so JDK 17/21 javac eagerly enumerates
ServiceLoader<Plugin> providers from the processor path (or, if absent,
the compile classpath). During incremental compilation our own
META-INF/services/com.sun.source.util.Plugin descriptor sits on the
classpath but SemanticdbPlugin.class isn't built yet, so ServiceLoader
throws 'Provider com.sourcegraph.semanticdb_javac.SemanticdbPlugin not
found'.
Fix: pass an explicit empty -processorpath to javac so it doesn't scan
our own output directory for Plugin providers. The descriptor stays in
src/main/resources/ so that internal sbt consumers (e.g. the
'minimized' test project that depends on javacPlugin via dependsOn)
and the Bazel build can still find it.
2. javadoc rejects the '-g' flag that was previously added via
'javacOptions += "-g"'. The old plugin worked around this with
'(doc / javacOptions) --= List("-g")'.
Fix: scope '-g' to 'Compile / javacOptions' so it never reaches the
doc task.
3. sbt-assembly's shader ships an older ASM that cannot read class major
version 61 (JDK 17). When sbt runs under JDK 17/21 the fat jar ends up
with SemanticdbVisitor (and other classes that hit protobuf types)
silently un-shaded, so at runtime javac fails with
'NoClassDefFoundError: com/google/protobuf/ProtocolMessageEnum'.
Fix: add 'Compile / javacOptions ++= Seq("--release", "11")' to
javaOnlySettings so Java code always emits class version 55, which the
shader handles, regardless of which JDK runs sbt.1 parent ab315b6 commit 2b14b77
1 file changed
Lines changed: 20 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
128 | 141 | | |
129 | 142 | | |
130 | 143 | | |
| |||
635 | 648 | | |
636 | 649 | | |
637 | 650 | | |
638 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
639 | 657 | | |
640 | 658 | | |
641 | 659 | | |
| |||
0 commit comments