From 4ebccb09d37a9bd69684758186f1a8e579047b28 Mon Sep 17 00:00:00 2001 From: Wojciech Mazur Date: Fri, 14 Nov 2025 13:11:24 +0100 Subject: [PATCH] Setup `doc / scalaInstance` instance to be used when building docs. Enable `packageDoc / publishArtifact` for bootstrapped projects - javadoc is required by Sonatype validation --- project/Build.scala | 59 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 33e74fea44fc..4e1f49913f24 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -198,12 +198,12 @@ object Build { "-encoding", "UTF8", "-language:implicitConversions", s"--java-output-version:${Versions.minimumJVMVersion}", - "-Yexplicit-nulls", + "-Yexplicit-nulls", "-Wsafe-init" ), (Compile / compile / javacOptions) ++= Seq( - "-Xlint:unchecked", + "-Xlint:unchecked", "-Xlint:deprecation", "--release", Versions.minimumJVMVersion ), @@ -448,6 +448,34 @@ object Build { ) ++ extMap } + // Setups up doc / scalaInstance to use in the bootstrapped projects instead of the default one + lazy val scaladocDerivedInstanceSettings = Def.settings( + // We cannot include scaladoc in the regular `scalaInstance` task because + // it's a bootstrapped-only project, so we would run into a loop since we + // need the output of that task to compile scaladoc. But we can include it + // in the `scalaInstance` of the `doc` task which allows us to run + // `scala3-library-bootstrapped/doc` for example. + doc / scalaInstance := { + val externalDeps = (LocalProject("scaladoc-new") / Compile / externalDependencyClasspath).value.map(_.data) + val scalaDoc = (LocalProject("scaladoc-new") / Compile / packageBin).value + val docJars = Array(scalaDoc) ++ externalDeps + + val base = scalaInstance.value + val docScalaInstance = Defaults.makeScalaInstance( + version = base.version, + libraryJars = base.libraryJars, + allCompilerJars = base.compilerJars, + allDocJars = docJars, + state.value, + scalaInstanceTopLoader.value + ) + // assert that sbt reuses the same compiler class loader + assert(docScalaInstance.loaderCompilerOnly == base.loaderCompilerOnly) + docScalaInstance + }, + Compile / doc / scalacOptions ++= scalacOptionsDocSettings(), + ) + // Settings used when compiling dotty with a non-bootstrapped dotty lazy val commonBootstrappedSettings = commonDottySettings ++ Seq( // To enable support of scaladoc and language-server projects you need to change this to true @@ -931,7 +959,7 @@ object Build { ), // Packaging configuration of `scala3-sbt-bridge` Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -963,6 +991,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -989,7 +1018,7 @@ object Build { Test / unmanagedSourceDirectories := Seq(baseDirectory.value / "test"), // Packaging configuration of `scala3-staging` Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1018,6 +1047,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1045,7 +1075,7 @@ object Build { // Make sure that the produced artifacts have the minimum JVM version in the bytecode // Packaging configuration of `scala3-staging` Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1074,6 +1104,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1098,7 +1129,7 @@ object Build { Test / unmanagedResourceDirectories := Seq(baseDirectory.value / "test-resources"), // Packaging configuration of `scala3-staging` Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1138,6 +1169,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1299,7 +1331,7 @@ object Build { ), // Packaging configuration of the stdlib Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1332,6 +1364,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1436,7 +1469,7 @@ object Build { }, // Packaging configuration of the stdlib Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1497,6 +1530,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1647,7 +1681,7 @@ object Build { ), // Packaging configuration of the stdlib Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1679,6 +1713,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -1871,7 +1906,7 @@ object Build { packageOptions += ManifestAttributes(("Git-Hash", VersionUtil.gitHash)), // Used by the REPL // Packaging configuration of the stdlib Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -1905,6 +1940,7 @@ object Build { scalaInstanceTopLoader.value ) }, + scaladocDerivedInstanceSettings, scalaCompilerBridgeBinaryJar := { Some((`scala3-sbt-bridge-nonbootstrapped` / Compile / packageBin).value) }, @@ -2019,7 +2055,7 @@ object Build { Compile / scalacOptions += "-experimental", // Packaging configuration of the stdlib Compile / packageBin / publishArtifact := true, - Compile / packageDoc / publishArtifact := false, + Compile / packageDoc / publishArtifact := true, Compile / packageSrc / publishArtifact := true, // Only publish compilation artifacts, no test artifacts Test / publishArtifact := false, @@ -2033,6 +2069,7 @@ object Build { BuildInfoPlugin.buildInfoDefaultSettings, // Configure to use the non-bootstrapped compiler managedScalaInstance := false, + scaladocDerivedInstanceSettings, scalaInstance := { val externalCompilerDeps = (`scala3-compiler-nonbootstrapped` / Compile / externalDependencyClasspath).value.map(_.data).toSet