mirror of https://github.com/sbt/sbt.git
feat: plugin cross building as Scala cross building
**Problem** Since Scala cross building works better than the plugin cross building `^^`, it was common for plugin authors to encode plugin cross building as Scala cross building given that we usually have zero or one sbt release in one Scala version. **Solution** This brings in the setting into SbtPlugin so plugin authors can cross build using sbt 2.x.
This commit is contained in:
parent
354dd25988
commit
01d5f9c050
|
|
@ -332,9 +332,6 @@ object Defaults extends BuildCommon {
|
||||||
envVars :== Map.empty,
|
envVars :== Map.empty,
|
||||||
sbtVersion := appConfiguration.value.provider.id.version,
|
sbtVersion := appConfiguration.value.provider.id.version,
|
||||||
sbtBinaryVersion := binarySbtVersion(sbtVersion.value),
|
sbtBinaryVersion := binarySbtVersion(sbtVersion.value),
|
||||||
// `pluginCrossBuild` scoping is based on sbt-cross-building plugin.
|
|
||||||
// The idea here is to be able to define a `sbtVersion in pluginCrossBuild`, which
|
|
||||||
// directs the dependencies of the plugin to build to the specified sbt plugin version.
|
|
||||||
pluginCrossBuild / sbtVersion := sbtVersion.value,
|
pluginCrossBuild / sbtVersion := sbtVersion.value,
|
||||||
onLoad := idFun[State],
|
onLoad := idFun[State],
|
||||||
onUnload := idFun[State],
|
onUnload := idFun[State],
|
||||||
|
|
@ -3102,7 +3099,7 @@ object Classpaths {
|
||||||
Defaults.globalDefaults(
|
Defaults.globalDefaults(
|
||||||
Seq(
|
Seq(
|
||||||
publishMavenStyle :== true,
|
publishMavenStyle :== true,
|
||||||
sbtPluginPublishLegacyMavenStyle :== true,
|
sbtPluginPublishLegacyMavenStyle :== false,
|
||||||
publishArtifact :== true,
|
publishArtifact :== true,
|
||||||
(Test / publishArtifact) :== false
|
(Test / publishArtifact) :== false
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,19 @@ package sbt
|
||||||
package plugins
|
package plugins
|
||||||
|
|
||||||
import sbt.Def.Setting
|
import sbt.Def.Setting
|
||||||
import sbt.Keys._
|
import sbt.Keys.*
|
||||||
|
import sbt.SlashSyntax0.*
|
||||||
|
|
||||||
object SbtPlugin extends AutoPlugin {
|
object SbtPlugin extends AutoPlugin:
|
||||||
override def requires = ScriptedPlugin
|
override def requires = ScriptedPlugin
|
||||||
|
|
||||||
override lazy val projectSettings: Seq[Setting[_]] = Seq(
|
override lazy val projectSettings: Seq[Setting[_]] = Seq(
|
||||||
sbtPlugin := true
|
sbtPlugin := true,
|
||||||
|
pluginCrossBuild / sbtVersion := {
|
||||||
|
scalaBinaryVersion.value match
|
||||||
|
case "3" => sbtVersion.value
|
||||||
|
case "2.12" => "1.5.8"
|
||||||
|
case "2.10" => "0.13.18"
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
end SbtPlugin
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
val scala3 = "3.3.3"
|
||||||
|
val scala212 = "2.12.19"
|
||||||
|
|
||||||
|
organization := "com.example"
|
||||||
|
version := "0.1.0-SNAPSHOT"
|
||||||
|
|
||||||
|
lazy val checkSbt2Plugin = taskKey[Unit]("")
|
||||||
|
|
||||||
|
lazy val plugin = (projectMatrix in file("plugin"))
|
||||||
|
.enablePlugins(SbtPlugin)
|
||||||
|
.settings(
|
||||||
|
organization := "com.example",
|
||||||
|
name := "sbt-example",
|
||||||
|
// TODO: Once 2.0 is released we can move this check to the `test` file
|
||||||
|
checkSbt2Plugin := {
|
||||||
|
val repo = (ThisBuild / baseDirectory).value / "repo"
|
||||||
|
val sbtV = sbtBinaryVersion.value
|
||||||
|
val expected = (repo / "com" / "example" /
|
||||||
|
s"sbt-example_sbt${sbtV}_3" /
|
||||||
|
"0.1.0-SNAPSHOT" /
|
||||||
|
s"sbt-example_sbt${sbtV}_3-0.1.0-SNAPSHOT.pom")
|
||||||
|
assert(expected.exists, s"$expected did not exist")
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.jvmPlatform(scalaVersions = Seq(scala3, scala212))
|
||||||
|
|
||||||
|
publishMavenStyle := true
|
||||||
|
publishTo := Some(Resolver.file("test-publish", (ThisBuild / baseDirectory).value / "repo/"))
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
> compile
|
||||||
|
|
||||||
|
> publish
|
||||||
|
|
||||||
|
$ exists repo/com/example/sbt-example_2.12_1.0/0.1.0-SNAPSHOT/sbt-example_2.12_1.0-0.1.0-SNAPSHOT.pom
|
||||||
|
$ absent repo/com/example/sbt-example_2.12_1.0/0.1.0-SNAPSHOT/sbt-example-0.1.0-SNAPSHOT.pom
|
||||||
|
|
||||||
|
> checkSbt2Plugin
|
||||||
Loading…
Reference in New Issue