Skip to content

Commit e7ea166

Browse files
committed
Fix javac plugin compilation under JDK 17+
JavaToolchainPlugin (now removed) used to mask two JDK-17+ issues in the javacPlugin project by pinning its compile JDK to 11 and stripping flags from the doc task. With the plugin gone, both issues surface: 1. JDK 14 added Plugin.autoStart(), so JDK 17/21 javac eagerly enumerates ServiceLoader<Plugin> providers from the compile classpath. During incremental compilation our META-INF/services/com.sun.source.util.Plugin descriptor lives on the classpath but SemanticdbPlugin.class isn't built yet, so ServiceLoader throws 'Provider ... not found'. Fix: move the descriptor from src/main/resources/ to src/main/assembly-resources/ and inject that directory only into the assembled fat jar via 'assembly / fullClasspath'. The descriptor is absent from the compile classpath but still bundled in the published jar. 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.
1 parent ab315b6 commit e7ea166

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

build.sbt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,16 @@ lazy val javacPlugin = project
124124
fatjarPackageSettings,
125125
javaOnlySettings,
126126
moduleName := "semanticdb-javac",
127-
javacOptions += "-g",
127+
Compile / javacOptions += "-g",
128+
// The META-INF/services/com.sun.source.util.Plugin descriptor lives in
129+
// src/main/assembly-resources/ instead of src/main/resources/ so that
130+
// it ends up in the assembled fat jar but is NOT on the compile
131+
// classpath. Otherwise JDK 14+ javac eagerly loads Plugin providers via
132+
// ServiceLoader during compilation and trips on the not-yet-compiled
133+
// SemanticdbPlugin class.
134+
assembly / fullClasspath += Attributed.blank(
135+
baseDirectory.value / "src" / "main" / "assembly-resources"
136+
),
128137
(assembly / assemblyShadeRules) :=
129138
Seq(
130139
ShadeRule

semanticdb-javac/src/main/resources/META-INF/services/com.sun.source.util.Plugin renamed to semanticdb-javac/src/main/assembly-resources/META-INF/services/com.sun.source.util.Plugin

File renamed without changes.

0 commit comments

Comments
 (0)