From eb7c0197a662bc96334a31a9e9200bedb79f768f Mon Sep 17 00:00:00 2001 From: jupblb Date: Wed, 24 Jun 2026 08:26:55 +0200 Subject: [PATCH] Clean up sbt project layout --- build.sbt | 213 +++++++++++++++++++++++++++--------------------------- 1 file changed, 107 insertions(+), 106 deletions(-) diff --git a/build.sbt b/build.sbt index ab4719df..3dd9bcf2 100644 --- a/build.sbt +++ b/build.sbt @@ -51,18 +51,6 @@ lazy val scipShared = project "org.scip-code" % "scip-java-bindings" % V.scipBindings ) -lazy val gradlePlugin = project - .in(file("scip-gradle-plugin")) - .settings( - name := "scip-gradle", - publish / skip := true, - libraryDependencies ++= - List( - "dev.gradleplugins" % "gradle-api" % V.gradle % Provided, - "dev.gradleplugins" % "gradle-test-kit" % V.gradle % Provided - ) - ) - lazy val javacPlugin = project .in(file("scip-javac")) .settings( @@ -124,23 +112,103 @@ lazy val javacPlugin = project ) .dependsOn(scipShared) -lazy val scip = project - .in(file("scip-aggregator")) +// The scip-kotlinc compiler plugin. Built as a fat-jar that is later +// embedded into the scip-java CLI distribution (see cli's resourceGenerators) +// so the runtime no longer needs to fetch a published scip-kotlinc +// artifact from Maven. +lazy val scipKotlinc = project + .in(file("scip-kotlinc")) + .enablePlugins(KotlinPlugin) .settings( - moduleName := "scip-aggregator", + name := "scip-kotlinc", + moduleName := "scip-kotlinc", + description := "A kotlinc plugin to emit SCIP information", + kotlinVersion := V.kotlinVersion, + kotlincJvmTarget := "1.8", + kotlincOptions ++= Seq("-Xinline-classes", "-Xcontext-parameters"), + // sbt-kotlin-plugin defaults to adding `kotlin-scripting-compiler-embeddable` + // (and its transitive kotlin-stdlib) as a regular dependency. Mark them + // Provided — kotlinc supplies them at runtime, and we don't want them + // bundled into the fat-jar. + kotlinRuntimeProvided := true, + // kotlin-stdlib is supplied by kotlinc at runtime — keep on compile + // classpath via Provided so the assembled fat-jar does not bundle it. + libraryDependencies += + "org.jetbrains.kotlin" % "kotlin-stdlib" % V.kotlinVersion % Provided, + // SCIP message classes come from scipShared (which depends on + // scip-java-bindings); this adds the Kotlin DSL extensions on top. + libraryDependencies += + "org.scip-code" % "scip-kotlin-bindings" % V.scipBindings, + // kotlin-compiler-embeddable is supplied by kotlinc at runtime + libraryDependencies += "org.jetbrains.kotlin" % + "kotlin-compiler-embeddable" % V.kotlinVersion % Provided, + // ---- sbt-assembly fat-jar --------------------------------------------- + // Produces a shaded jar for consumers that need a self-contained compiler + // plugin, such as the CLI resource embedding and minimized fixture build. + assembly / assemblyShadeRules := + Seq( + // Relocate any IntelliJ classes the same way kotlin-compiler-embeddable + // does internally. Do NOT rename `com.sourcegraph.**` — the + // META-INF/services files reference those FQNs. + ShadeRule + .rename("com.intellij.**" -> "org.jetbrains.kotlin.com.intellij.@1") + .inAll + ), + // tests libraryDependencies ++= Seq( - "org.scip-code" % "scip-java-bindings" % V.scipBindings, - // JUnit 5 for the colocated Java unit tests (test scope only, so it is - // excluded from the published POM and keeps this a Java-only module). + "org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % + V.kotlinVersion % Test, + "org.jetbrains.kotlin" % "kotlin-test" % V.kotlinVersion % Test, + "org.jetbrains.kotlin" % "kotlin-test-junit5" % V.kotlinVersion % Test, + "org.jetbrains.kotlin" % "kotlin-reflect" % V.kotlinVersion % Test, + "io.kotest" % "kotest-assertions-core-jvm" % V.kotest % Test, + "dev.zacsweers.kctfork" % "core" % V.kctfork % Test, "com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test ), - (Compile / PB.targets) := - Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value) + Test / fork := true, + Test / javaOptions += "-Xmx2g", + // sbt-kotlin-plugin 3.1.6 inspects every jar on the kotlinc classpath and + // moves any jar containing META-INF/services/org.jetbrains.kotlin.compiler.plugin.* + // entries into the compiler-plugin classpath, removing it from the regular + // classpath. kctfork ships such service files for its own internal use as a + // KAPT/registrar shim, which makes its public API (com.tschuchort.compiletesting.*) + // invisible to our test sources. Workaround: pre-extract kctfork to a + // directory and add that directory to the test classpath — sbt-kotlin-plugin + // only inspects .jar files, so directories pass through unmodified. + Test / unmanagedJars += { + val report = update.value + val files = report.allFiles + val jar = files + .find(_.getName == s"core-${V.kctfork}.jar") + .getOrElse( + sys.error(s"kctfork core-${V.kctfork}.jar not found in update report") + ) + val dir = target.value / s"kctfork-${V.kctfork}-extracted" + val marker = dir / ".extracted" + if (!marker.exists()) { + IO.delete(dir) + IO.unzip(jar, dir) + IO.touch(marker) + } + Attributed.blank(dir) + } ) .dependsOn(scipShared) +lazy val gradlePlugin = project + .in(file("scip-gradle-plugin")) + .settings( + name := "scip-gradle", + publish / skip := true, + libraryDependencies ++= + List( + "dev.gradleplugins" % "gradle-api" % V.gradle % Provided, + "dev.gradleplugins" % "gradle-test-kit" % V.gradle % Provided + ) + ) + lazy val mavenPlugin = project .in(file("scip-maven-plugin")) .settings( @@ -169,6 +237,24 @@ lazy val mavenPlugin = project } ) +// Aggregates compiler-plugin shards into the final SCIP index consumed by the CLI. +lazy val scipAggregator = project + .in(file("scip-aggregator")) + .settings( + moduleName := "scip-aggregator", + libraryDependencies ++= + Seq( + "org.scip-code" % "scip-java-bindings" % V.scipBindings, + // JUnit 5 for the colocated Java unit tests (test scope only, so it is + // excluded from the published POM and keeps this a Java-only module). + "com.github.sbt.junit" % "jupiter-interface" % + JupiterKeys.jupiterVersion.value % Test + ), + (Compile / PB.targets) := + Seq(PB.gens.java(V.protobuf) -> (Compile / sourceManaged).value) + ) + .dependsOn(scipShared) + lazy val cli = project .in(file("scip-java")) .enablePlugins(KotlinPlugin, PackPlugin) @@ -239,92 +325,7 @@ lazy val cli = project } .taskValue ) - .dependsOn(scip) - -// The scip-kotlinc compiler plugin. Built as a fat-jar that is later -// embedded into the scip-java CLI distribution (see cli's resourceGenerators) -// so the runtime no longer needs to fetch a published scip-kotlinc -// artifact from Maven. -lazy val scipKotlinc = project - .in(file("scip-kotlinc")) - .enablePlugins(KotlinPlugin) - .settings( - name := "scip-kotlinc", - moduleName := "scip-kotlinc", - description := "A kotlinc plugin to emit SCIP information", - kotlinVersion := V.kotlinVersion, - kotlincJvmTarget := "1.8", - kotlincOptions ++= Seq("-Xinline-classes", "-Xcontext-parameters"), - // sbt-kotlin-plugin defaults to adding `kotlin-scripting-compiler-embeddable` - // (and its transitive kotlin-stdlib) as a regular dependency. Mark them - // Provided — kotlinc supplies them at runtime, and we don't want them - // bundled into the fat-jar. - kotlinRuntimeProvided := true, - // kotlin-stdlib is supplied by kotlinc at runtime — keep on compile - // classpath via Provided so the assembled fat-jar does not bundle it. - libraryDependencies += - "org.jetbrains.kotlin" % "kotlin-stdlib" % V.kotlinVersion % Provided, - // SCIP message classes come from scipShared (which depends on - // scip-java-bindings); this adds the Kotlin DSL extensions on top. - libraryDependencies += - "org.scip-code" % "scip-kotlin-bindings" % V.scipBindings, - // kotlin-compiler-embeddable is supplied by kotlinc at runtime - libraryDependencies += "org.jetbrains.kotlin" % - "kotlin-compiler-embeddable" % V.kotlinVersion % Provided, - // ---- sbt-assembly fat-jar --------------------------------------------- - // Produces a shaded jar for consumers that need a self-contained compiler - // plugin, such as the CLI resource embedding and minimized fixture build. - assembly / assemblyShadeRules := - Seq( - // Relocate any IntelliJ classes the same way kotlin-compiler-embeddable - // does internally. Do NOT rename `com.sourcegraph.**` — the - // META-INF/services files reference those FQNs. - ShadeRule - .rename("com.intellij.**" -> "org.jetbrains.kotlin.com.intellij.@1") - .inAll - ), - // tests - libraryDependencies ++= - Seq( - "org.jetbrains.kotlin" % "kotlin-compiler-embeddable" % - V.kotlinVersion % Test, - "org.jetbrains.kotlin" % "kotlin-test" % V.kotlinVersion % Test, - "org.jetbrains.kotlin" % "kotlin-test-junit5" % V.kotlinVersion % Test, - "org.jetbrains.kotlin" % "kotlin-reflect" % V.kotlinVersion % Test, - "io.kotest" % "kotest-assertions-core-jvm" % V.kotest % Test, - "dev.zacsweers.kctfork" % "core" % V.kctfork % Test, - "com.github.sbt.junit" % "jupiter-interface" % - JupiterKeys.jupiterVersion.value % Test - ), - Test / fork := true, - Test / javaOptions += "-Xmx2g", - // sbt-kotlin-plugin 3.1.6 inspects every jar on the kotlinc classpath and - // moves any jar containing META-INF/services/org.jetbrains.kotlin.compiler.plugin.* - // entries into the compiler-plugin classpath, removing it from the regular - // classpath. kctfork ships such service files for its own internal use as a - // KAPT/registrar shim, which makes its public API (com.tschuchort.compiletesting.*) - // invisible to our test sources. Workaround: pre-extract kctfork to a - // directory and add that directory to the test classpath — sbt-kotlin-plugin - // only inspects .jar files, so directories pass through unmodified. - Test / unmanagedJars += { - val report = update.value - val files = report.allFiles - val jar = files - .find(_.getName == s"core-${V.kctfork}.jar") - .getOrElse( - sys.error(s"kctfork core-${V.kctfork}.jar not found in update report") - ) - val dir = target.value / s"kctfork-${V.kctfork}-extracted" - val marker = dir / ".extracted" - if (!marker.exists()) { - IO.delete(dir) - IO.unzip(jar, dir) - IO.touch(marker) - } - Attributed.blank(dir) - } - ) - .dependsOn(scipShared) + .dependsOn(scipAggregator) // Kotlin snapshot case. The fixture includes Java sources as interop // consumers, but the case is still keyed by the Kotlin compiler/plugin version