mirror of https://github.com/sbt/sbt.git
feat: Use _sbt2_3 suffix
**Problem** The extra attribute is a vestige from the days when sbt plugins were published on Ivy repos. **Solution** This uses normal suffix system.
This commit is contained in:
parent
2565b8c904
commit
ddeb5dba2c
|
|
@ -2585,11 +2585,20 @@ object Defaults extends BuildCommon {
|
||||||
}
|
}
|
||||||
|
|
||||||
def sbtPluginExtra(m: ModuleID, sbtV: String, scalaV: String): ModuleID =
|
def sbtPluginExtra(m: ModuleID, sbtV: String, scalaV: String): ModuleID =
|
||||||
m.extra(
|
partialVersion(sbtV) match {
|
||||||
PomExtraDependencyAttributes.SbtVersionKey -> sbtV,
|
case Some((0, _)) | Some((1, _)) =>
|
||||||
PomExtraDependencyAttributes.ScalaVersionKey -> scalaV
|
m.extra(
|
||||||
)
|
PomExtraDependencyAttributes.SbtVersionKey -> sbtV,
|
||||||
.withCrossVersion(Disabled())
|
PomExtraDependencyAttributes.ScalaVersionKey -> scalaV
|
||||||
|
)
|
||||||
|
.withCrossVersion(Disabled())
|
||||||
|
case Some(_) =>
|
||||||
|
// this produces a normal suffix like _sjs1_2.13
|
||||||
|
val prefix = s"sbt${binarySbtVersion(sbtV)}_"
|
||||||
|
m.cross(CrossVersion.binaryWith(prefix, ""))
|
||||||
|
case None =>
|
||||||
|
sys.error(s"unknown sbt version $sbtV")
|
||||||
|
}
|
||||||
|
|
||||||
def discoverSbtPluginNames: Initialize[Task[PluginDiscovery.DiscoveredNames]] = Def.taskDyn {
|
def discoverSbtPluginNames: Initialize[Task[PluginDiscovery.DiscoveredNames]] = Def.taskDyn {
|
||||||
if (sbtPlugin.value) Def.task(PluginDiscovery.discoverSourceAll(compile.value))
|
if (sbtPlugin.value) Def.task(PluginDiscovery.discoverSourceAll(compile.value))
|
||||||
|
|
@ -2913,7 +2922,7 @@ object Classpaths {
|
||||||
Defaults.globalDefaults(
|
Defaults.globalDefaults(
|
||||||
Seq(
|
Seq(
|
||||||
publishMavenStyle :== true,
|
publishMavenStyle :== true,
|
||||||
sbtPluginPublishLegacyMavenStyle := true,
|
sbtPluginPublishLegacyMavenStyle :== true,
|
||||||
publishArtifact :== true,
|
publishArtifact :== true,
|
||||||
(Test / publishArtifact) :== false
|
(Test / publishArtifact) :== false
|
||||||
)
|
)
|
||||||
|
|
@ -2921,8 +2930,10 @@ object Classpaths {
|
||||||
|
|
||||||
private lazy val publishSbtPluginMavenStyle = Def.task(sbtPlugin.value && publishMavenStyle.value)
|
private lazy val publishSbtPluginMavenStyle = Def.task(sbtPlugin.value && publishMavenStyle.value)
|
||||||
private lazy val packagedDefaultArtifacts = packaged(defaultArtifactTasks)
|
private lazy val packagedDefaultArtifacts = packaged(defaultArtifactTasks)
|
||||||
private lazy val emptyArtifacts = Def.task(Map.empty[Artifact, File])
|
private lazy val sbt2Plus: Def.Initialize[Boolean] = Def.setting {
|
||||||
|
val sbtV = (pluginCrossBuild / sbtBinaryVersion).value
|
||||||
|
sbtV != "1.0" && !sbtV.startsWith("0.")
|
||||||
|
}
|
||||||
val jvmPublishSettings: Seq[Setting[_]] = Seq(
|
val jvmPublishSettings: Seq[Setting[_]] = Seq(
|
||||||
artifacts := artifactDefs(defaultArtifactTasks).value,
|
artifacts := artifactDefs(defaultArtifactTasks).value,
|
||||||
packagedArtifacts := Def
|
packagedArtifacts := Def
|
||||||
|
|
@ -2943,12 +2954,30 @@ object Classpaths {
|
||||||
*/
|
*/
|
||||||
private def mavenArtifactsOfSbtPlugin: Def.Initialize[Task[Map[Artifact, File]]] =
|
private def mavenArtifactsOfSbtPlugin: Def.Initialize[Task[Map[Artifact, File]]] =
|
||||||
Def.task {
|
Def.task {
|
||||||
val crossVersion = sbtCrossVersion.value
|
// This is a conditional task. The top-level must be an if expression.
|
||||||
val legacyArtifact = (makePom / artifact).value
|
if (sbt2Plus.value) {
|
||||||
val pom = makeMavenPomOfSbtPlugin.value
|
// Both POMs and JARs are Maven-compatible in sbt 2.x, so ignore the workarounds
|
||||||
val legacyPackages = packaged(defaultPackages).value
|
packagedDefaultArtifacts.value
|
||||||
|
} else {
|
||||||
|
val crossVersion = sbtCrossVersion.value
|
||||||
|
val legacyPomArtifact = (makePom / artifact).value
|
||||||
|
def addSuffix(a: Artifact): Artifact = a.withName(crossVersion(a.name))
|
||||||
|
Map(addSuffix(legacyPomArtifact) -> makeMavenPomOfSbtPlugin.value) ++
|
||||||
|
pomConsistentArtifactsForLegacySbt.value ++
|
||||||
|
legacyPackagedArtifacts.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def addSuffix(a: Artifact): Artifact = a.withName(crossVersion(a.name))
|
private def legacyPackagedArtifacts: Def.Initialize[Task[Map[Artifact, File]]] = Def.task {
|
||||||
|
// This is a conditional task. The top-level must be an if expression.
|
||||||
|
if (sbtPluginPublishLegacyMavenStyle.value) packagedDefaultArtifacts.value
|
||||||
|
else Map.empty[Artifact, File]
|
||||||
|
}
|
||||||
|
|
||||||
|
private def pomConsistentArtifactsForLegacySbt: Def.Initialize[Task[Map[Artifact, File]]] =
|
||||||
|
Def.task {
|
||||||
|
val crossVersion = sbtCrossVersion.value
|
||||||
|
val legacyPackages = packaged(defaultPackages).value
|
||||||
def copyArtifact(artifact: Artifact, file: File): (Artifact, File) = {
|
def copyArtifact(artifact: Artifact, file: File): (Artifact, File) = {
|
||||||
val nameWithSuffix = crossVersion(artifact.name)
|
val nameWithSuffix = crossVersion(artifact.name)
|
||||||
val targetFile =
|
val targetFile =
|
||||||
|
|
@ -2956,11 +2985,9 @@ object Classpaths {
|
||||||
IO.copyFile(file, targetFile)
|
IO.copyFile(file, targetFile)
|
||||||
artifact.withName(nameWithSuffix) -> targetFile
|
artifact.withName(nameWithSuffix) -> targetFile
|
||||||
}
|
}
|
||||||
val packages = legacyPackages.map { case (artifact, file) => copyArtifact(artifact, file) }
|
legacyPackages.map {
|
||||||
val legacyPackagedArtifacts = Def
|
case (artifact, file) => copyArtifact(artifact, file);
|
||||||
.ifS(sbtPluginPublishLegacyMavenStyle.toTask)(packagedDefaultArtifacts)(emptyArtifacts)
|
}
|
||||||
.value
|
|
||||||
packages + (addSuffix(legacyArtifact) -> pom) ++ legacyPackagedArtifacts
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def sbtCrossVersion: Def.Initialize[String => String] = Def.setting {
|
private def sbtCrossVersion: Def.Initialize[String => String] = Def.setting {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue