Skip to content

Commit dddc6c5

Browse files
authored
Clean up sbt project layout (#923)
1 parent aa23f1c commit dddc6c5

1 file changed

Lines changed: 107 additions & 106 deletions

File tree

build.sbt

Lines changed: 107 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ lazy val scipShared = project
5151
"org.scip-code" % "scip-java-bindings" % V.scipBindings
5252
)
5353

54-
lazy val gradlePlugin = project
55-
.in(file("scip-gradle-plugin"))
56-
.settings(
57-
name := "scip-gradle",
58-
publish / skip := true,
59-
libraryDependencies ++=
60-
List(
61-
"dev.gradleplugins" % "gradle-api" % V.gradle % Provided,
62-
"dev.gradleplugins" % "gradle-test-kit" % V.gradle % Provided
63-
)
64-
)
65-
6654
lazy val javacPlugin = project
6755
.in(file("scip-javac"))
6856
.settings(
@@ -124,23 +112,103 @@ lazy val javacPlugin = project
124112
)
125113
.dependsOn(scipShared)
126114

127-
lazy val scip = project
128-
.in(file("scip-aggregator"))
115+
// The scip-kotlinc compiler plugin. Built as a fat-jar that is later
116+
// embedded into the scip-java CLI distribution (see cli's resourceGenerators)
117+
// so the runtime no longer needs to fetch a published scip-kotlinc
118+
// artifact from Maven.
119+
lazy val scipKotlinc = project
120+
.in(file("scip-kotlinc"))
121+
.enablePlugins(KotlinPlugin)
129122
.settings(
130-
moduleName := "scip-aggregator",
123+
name := "scip-kotlinc",
124+
moduleName := "scip-kotlinc",
125+
description := "A kotlinc plugin to emit SCIP information",
126+
kotlinVersion := V.kotlinVersion,
127+
kotlincJvmTarget := "1.8",
128+
kotlincOptions ++= Seq("-Xinline-classes", "-Xcontext-parameters"),
129+
// sbt-kotlin-plugin defaults to adding `kotlin-scripting-compiler-embeddable`
130+
// (and its transitive kotlin-stdlib) as a regular dependency. Mark them
131+
// Provided — kotlinc supplies them at runtime, and we don't want them
132+
// bundled into the fat-jar.
133+
kotlinRuntimeProvided := true,
134+
// kotlin-stdlib is supplied by kotlinc at runtime — keep on compile
135+
// classpath via Provided so the assembled fat-jar does not bundle it.
136+
libraryDependencies +=
137+
"org.jetbrains.kotlin" % "kotlin-stdlib" % V.kotlinVersion % Provided,
138+
// SCIP message classes come from scipShared (which depends on
139+
// scip-java-bindings); this adds the Kotlin DSL extensions on top.
140+
libraryDependencies +=
141+
"org.scip-code" % "scip-kotlin-bindings" % V.scipBindings,
142+
// kotlin-compiler-embeddable is supplied by kotlinc at runtime
143+
libraryDependencies += "org.jetbrains.kotlin" %
144+
"kotlin-compiler-embeddable" % V.kotlinVersion % Provided,
145+
// ---- sbt-assembly fat-jar ---------------------------------------------
146+
// Produces a shaded jar for consumers that need a self-contained compiler
147+
// plugin, such as the CLI resource embedding and minimized fixture build.
148+
assembly / assemblyShadeRules :=
149+
Seq(
150+
// Relocate any IntelliJ classes the same way kotlin-compiler-embeddable
151+
// does internally. Do NOT rename `com.sourcegraph.**` — the
152+
// META-INF/services files reference those FQNs.
153+
ShadeRule
154+
.rename("com.intellij.**" -> "org.jetbrains.kotlin.com.intellij.@1")
155+
.inAll
156+
),
157+
// tests
131158
libraryDependencies ++=
132159
Seq(
133-
"org.scip-code" % "scip-java-bindings" % V.scipBindings,
134-
// JUnit 5 for the colocated Java unit tests (test scope only, so it is
135-
// excluded from the published POM and keeps this a Java-only module).
160+
"org.jetbrains.kotlin" % "kotlin-compiler-embeddable" %
161+
V.kotlinVersion % Test,
162+
"org.jetbrains.kotlin" % "kotlin-test" % V.kotlinVersion % Test,
163+
"org.jetbrains.kotlin" % "kotlin-test-junit5" % V.kotlinVersion % Test,
164+
"org.jetbrains.kotlin" % "kotlin-reflect" % V.kotlinVersion % Test,
165+
"io.kotest" % "kotest-assertions-core-jvm" % V.kotest % Test,
166+
"dev.zacsweers.kctfork" % "core" % V.kctfork % Test,
136167
"com.github.sbt.junit" % "jupiter-interface" %
137168
JupiterKeys.jupiterVersion.value % Test
138169
),
139-
(Compile / PB.targets) :=
140-
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value)
170+
Test / fork := true,
171+
Test / javaOptions += "-Xmx2g",
172+
// sbt-kotlin-plugin 3.1.6 inspects every jar on the kotlinc classpath and
173+
// moves any jar containing META-INF/services/org.jetbrains.kotlin.compiler.plugin.*
174+
// entries into the compiler-plugin classpath, removing it from the regular
175+
// classpath. kctfork ships such service files for its own internal use as a
176+
// KAPT/registrar shim, which makes its public API (com.tschuchort.compiletesting.*)
177+
// invisible to our test sources. Workaround: pre-extract kctfork to a
178+
// directory and add that directory to the test classpath — sbt-kotlin-plugin
179+
// only inspects .jar files, so directories pass through unmodified.
180+
Test / unmanagedJars += {
181+
val report = update.value
182+
val files = report.allFiles
183+
val jar = files
184+
.find(_.getName == s"core-${V.kctfork}.jar")
185+
.getOrElse(
186+
sys.error(s"kctfork core-${V.kctfork}.jar not found in update report")
187+
)
188+
val dir = target.value / s"kctfork-${V.kctfork}-extracted"
189+
val marker = dir / ".extracted"
190+
if (!marker.exists()) {
191+
IO.delete(dir)
192+
IO.unzip(jar, dir)
193+
IO.touch(marker)
194+
}
195+
Attributed.blank(dir)
196+
}
141197
)
142198
.dependsOn(scipShared)
143199

200+
lazy val gradlePlugin = project
201+
.in(file("scip-gradle-plugin"))
202+
.settings(
203+
name := "scip-gradle",
204+
publish / skip := true,
205+
libraryDependencies ++=
206+
List(
207+
"dev.gradleplugins" % "gradle-api" % V.gradle % Provided,
208+
"dev.gradleplugins" % "gradle-test-kit" % V.gradle % Provided
209+
)
210+
)
211+
144212
lazy val mavenPlugin = project
145213
.in(file("scip-maven-plugin"))
146214
.settings(
@@ -169,6 +237,24 @@ lazy val mavenPlugin = project
169237
}
170238
)
171239

240+
// Aggregates compiler-plugin shards into the final SCIP index consumed by the CLI.
241+
lazy val scipAggregator = project
242+
.in(file("scip-aggregator"))
243+
.settings(
244+
moduleName := "scip-aggregator",
245+
libraryDependencies ++=
246+
Seq(
247+
"org.scip-code" % "scip-java-bindings" % V.scipBindings,
248+
// JUnit 5 for the colocated Java unit tests (test scope only, so it is
249+
// excluded from the published POM and keeps this a Java-only module).
250+
"com.github.sbt.junit" % "jupiter-interface" %
251+
JupiterKeys.jupiterVersion.value % Test
252+
),
253+
(Compile / PB.targets) :=
254+
Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value)
255+
)
256+
.dependsOn(scipShared)
257+
172258
lazy val cli = project
173259
.in(file("scip-java"))
174260
.enablePlugins(KotlinPlugin, PackPlugin)
@@ -239,92 +325,7 @@ lazy val cli = project
239325
}
240326
.taskValue
241327
)
242-
.dependsOn(scip)
243-
244-
// The scip-kotlinc compiler plugin. Built as a fat-jar that is later
245-
// embedded into the scip-java CLI distribution (see cli's resourceGenerators)
246-
// so the runtime no longer needs to fetch a published scip-kotlinc
247-
// artifact from Maven.
248-
lazy val scipKotlinc = project
249-
.in(file("scip-kotlinc"))
250-
.enablePlugins(KotlinPlugin)
251-
.settings(
252-
name := "scip-kotlinc",
253-
moduleName := "scip-kotlinc",
254-
description := "A kotlinc plugin to emit SCIP information",
255-
kotlinVersion := V.kotlinVersion,
256-
kotlincJvmTarget := "1.8",
257-
kotlincOptions ++= Seq("-Xinline-classes", "-Xcontext-parameters"),
258-
// sbt-kotlin-plugin defaults to adding `kotlin-scripting-compiler-embeddable`
259-
// (and its transitive kotlin-stdlib) as a regular dependency. Mark them
260-
// Provided — kotlinc supplies them at runtime, and we don't want them
261-
// bundled into the fat-jar.
262-
kotlinRuntimeProvided := true,
263-
// kotlin-stdlib is supplied by kotlinc at runtime — keep on compile
264-
// classpath via Provided so the assembled fat-jar does not bundle it.
265-
libraryDependencies +=
266-
"org.jetbrains.kotlin" % "kotlin-stdlib" % V.kotlinVersion % Provided,
267-
// SCIP message classes come from scipShared (which depends on
268-
// scip-java-bindings); this adds the Kotlin DSL extensions on top.
269-
libraryDependencies +=
270-
"org.scip-code" % "scip-kotlin-bindings" % V.scipBindings,
271-
// kotlin-compiler-embeddable is supplied by kotlinc at runtime
272-
libraryDependencies += "org.jetbrains.kotlin" %
273-
"kotlin-compiler-embeddable" % V.kotlinVersion % Provided,
274-
// ---- sbt-assembly fat-jar ---------------------------------------------
275-
// Produces a shaded jar for consumers that need a self-contained compiler
276-
// plugin, such as the CLI resource embedding and minimized fixture build.
277-
assembly / assemblyShadeRules :=
278-
Seq(
279-
// Relocate any IntelliJ classes the same way kotlin-compiler-embeddable
280-
// does internally. Do NOT rename `com.sourcegraph.**` — the
281-
// META-INF/services files reference those FQNs.
282-
ShadeRule
283-
.rename("com.intellij.**" -> "org.jetbrains.kotlin.com.intellij.@1")
284-
.inAll
285-
),
286-
// tests
287-
libraryDependencies ++=
288-
Seq(
289-
"org.jetbrains.kotlin" % "kotlin-compiler-embeddable" %
290-
V.kotlinVersion % Test,
291-
"org.jetbrains.kotlin" % "kotlin-test" % V.kotlinVersion % Test,
292-
"org.jetbrains.kotlin" % "kotlin-test-junit5" % V.kotlinVersion % Test,
293-
"org.jetbrains.kotlin" % "kotlin-reflect" % V.kotlinVersion % Test,
294-
"io.kotest" % "kotest-assertions-core-jvm" % V.kotest % Test,
295-
"dev.zacsweers.kctfork" % "core" % V.kctfork % Test,
296-
"com.github.sbt.junit" % "jupiter-interface" %
297-
JupiterKeys.jupiterVersion.value % Test
298-
),
299-
Test / fork := true,
300-
Test / javaOptions += "-Xmx2g",
301-
// sbt-kotlin-plugin 3.1.6 inspects every jar on the kotlinc classpath and
302-
// moves any jar containing META-INF/services/org.jetbrains.kotlin.compiler.plugin.*
303-
// entries into the compiler-plugin classpath, removing it from the regular
304-
// classpath. kctfork ships such service files for its own internal use as a
305-
// KAPT/registrar shim, which makes its public API (com.tschuchort.compiletesting.*)
306-
// invisible to our test sources. Workaround: pre-extract kctfork to a
307-
// directory and add that directory to the test classpath — sbt-kotlin-plugin
308-
// only inspects .jar files, so directories pass through unmodified.
309-
Test / unmanagedJars += {
310-
val report = update.value
311-
val files = report.allFiles
312-
val jar = files
313-
.find(_.getName == s"core-${V.kctfork}.jar")
314-
.getOrElse(
315-
sys.error(s"kctfork core-${V.kctfork}.jar not found in update report")
316-
)
317-
val dir = target.value / s"kctfork-${V.kctfork}-extracted"
318-
val marker = dir / ".extracted"
319-
if (!marker.exists()) {
320-
IO.delete(dir)
321-
IO.unzip(jar, dir)
322-
IO.touch(marker)
323-
}
324-
Attributed.blank(dir)
325-
}
326-
)
327-
.dependsOn(scipShared)
328+
.dependsOn(scipAggregator)
328329

329330
// Kotlin snapshot case. The fixture includes Java sources as interop
330331
// consumers, but the case is still keyed by the Kotlin compiler/plugin version

0 commit comments

Comments
 (0)