Make publishLocalBin work without prior publishLocal

In order for the sbt launcher to be able to resolve a local version of
sbt, we must publish the main jar, the sources jar, the doc jar, the pom
and an ivy.xml file. The publish and publishLocal tasks are wired in
IvyXml.scala to create an ivy.xml file before running publish. This
wasn't done with publishLocalBin which made it not work when no ivy.xml
file was already present (which was the case after running clean).
This commit is contained in:
Ethan Atkins 2020-01-12 13:20:41 -08:00
parent c18284948d
commit 17deb8b5d6
2 changed files with 50 additions and 17 deletions

View File

@ -180,7 +180,7 @@ object IvyXml {
</ivy-module>
}
private def makeIvyXmlBefore[T](
private[sbt] def makeIvyXmlBefore[T](
task: TaskKey[T],
shadedConfigOpt: Option[Configuration]
): Setting[Task[T]] =

View File

@ -1,7 +1,11 @@
import sbt._, Keys._
package sbt
import sbt.librarymanagement.PublishConfiguration
import sbt.librarymanagement.ConfigRef
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.{ FileAlreadyExistsException, Files }
import org.apache.ivy.core.module.id.ModuleRevisionId
import sbt.Keys._
import sbt.internal.librarymanagement.{ IvySbt, IvyXml }
/** This local plugin provides ways of publishing just the binary jar. */
object PublishBinPlugin extends AutoPlugin {
@ -13,22 +17,51 @@ object PublishBinPlugin extends AutoPlugin {
}
import autoImport._
override def globalSettings = Seq(publishLocalBin := (()))
private val dummyDoc = taskKey[File]("").withRank(Int.MaxValue)
override val globalSettings = Seq(publishLocalBin := (()))
override def projectSettings = Def settings (
override val projectSettings: Seq[Def.Setting[_]] = Def settings (
publishLocalBin := Classpaths.publishTask(publishLocalBinConfig).value,
publishLocalBinConfig := {
Classpaths.publishConfig(
false, // publishMavenStyle.value,
Classpaths.deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
(packagedArtifacts in publishLocalBin).value.toVector,
(checksums in publishLocalBin).value.toVector,
logging = ivyLoggingLevel.value,
overwrite = isSnapshot.value
publishLocalBinConfig := Classpaths.publishConfig(
false, // publishMavenStyle.value,
Classpaths.deliverPattern(crossTarget.value),
if (isSnapshot.value) "integration" else "release",
ivyConfigurations.value.map(c => ConfigRef(c.name)).toVector,
(packagedArtifacts in publishLocalBin).value.toVector,
(checksums in publishLocalBin).value.toVector,
logging = ivyLoggingLevel.value,
overwrite = isSnapshot.value
),
publishLocalBinConfig := publishLocalBinConfig
.dependsOn(
// Copied from sbt.internal.
Def.taskDyn {
val doGen = useCoursier.value
if (doGen)
Def.task {
val currentProject = {
val proj = csrProject.value
val publications = csrPublications.value
proj.withPublications(publications)
}
IvyXml.writeFiles(currentProject, None, ivySbt.value, streams.value.log)
} else
Def.task(())
}
)
.value,
dummyDoc := {
val dummyFile = streams.value.cacheDirectory / "doc.jar"
try {
Files.createDirectories(dummyFile.toPath.getParent)
Files.createFile(dummyFile.toPath)
} catch { case _: FileAlreadyExistsException => }
dummyFile
},
packagedArtifacts in publishLocalBin := Classpaths.packaged(Seq(packageBin in Compile)).value
dummyDoc / packagedArtifact := (Compile / packageDoc / artifact).value -> dummyDoc.value,
packagedArtifacts in publishLocalBin :=
Classpaths
.packaged(Seq(packageBin in Compile, packageSrc in Compile, makePom, dummyDoc))
.value
)
}