add includePluginResolvers

Fixes #5070

This adds a new setting called `includePluginResolvers` (default `false`).
When set to `true`, it the project will include resolvers from the metabuild.

This allows the build user to declare a resolver in one place (`project/plugins.sbt`) that gets applied to both the metabuild as well as all the subprojects. The scenario comes up when someone distributes a software on their own repo. Ref #4103
This commit is contained in:
Eugene Yokota 2019-09-17 23:04:10 -04:00
parent d119818656
commit 6664cbe2ae
5 changed files with 24 additions and 2 deletions

View File

@ -2174,6 +2174,7 @@ object Classpaths {
moduleConfigurations :== Nil,
publishTo :== None,
resolvers :== Vector.empty,
includePluginResolvers :== false,
useJCenter :== false,
retrievePattern :== Resolver.defaultRetrievePattern,
transitiveClassifiers :== Seq(SourceClassifier, DocClassifier),
@ -2246,10 +2247,21 @@ object Classpaths {
(Def.task {
val proj = projectResolver.value
val rs = externalResolvers.value
def pluginResolvers: Vector[Resolver] =
buildStructure.value
.units(thisProjectRef.value.build)
.unit
.plugins
.pluginData
.resolvers
.getOrElse(Vector.empty)
val pr =
if (includePluginResolvers.value) pluginResolvers
else Vector.empty
bootResolvers.value match {
case Some(repos) if overrideBuildResolvers.value => proj +: repos
case _ =>
val base = if (sbtPlugin.value) sbtResolvers.value ++ rs else rs
val base = if (sbtPlugin.value) sbtResolvers.value ++ rs ++ pr else rs ++ pr
(proj +: base).distinct
}
}).value,

View File

@ -411,7 +411,8 @@ object Keys {
val fullResolvers = taskKey[Seq[Resolver]]("Combines the project resolver, default resolvers, and user-defined resolvers.").withRank(CTask)
val otherResolvers = taskKey[Seq[Resolver]]("Resolvers not included in the main resolver chain, such as those in module configurations.").withRank(CSetting)
val scalaCompilerBridgeResolvers = taskKey[Seq[Resolver]]("Resolvers used to resolve compiler bridges.").withRank(CSetting)
val useJCenter = settingKey[Boolean]("Use JCenter as the default repository.").withRank(BSetting)
val includePluginResolvers = settingKey[Boolean]("Include the resolvers from the metabuild.").withRank(CSetting)
val useJCenter = settingKey[Boolean]("Use JCenter as the default repository.").withRank(CSetting)
val moduleConfigurations = settingKey[Seq[ModuleConfiguration]]("Defines module configurations, which override resolvers on a per-module basis.").withRank(BMinusSetting)
val retrievePattern = settingKey[String]("Pattern used to retrieve managed dependencies to the current build.").withRank(DSetting)
val retrieveConfiguration = settingKey[Option[RetrieveConfiguration]]("Configures retrieving dependencies to the current build.").withRank(DSetting)

View File

@ -0,0 +1,7 @@
lazy val check = taskKey[Unit]("")
ThisBuild / includePluginResolvers := true
check := {
val rs = fullResolvers.value
assert(rs exists (_.name == "bintray-eed3si9n-sbt-plugins"), s"$rs does not include bintray")
}

View File

@ -0,0 +1 @@
resolvers += Resolver.bintrayRepo("eed3si9n", "sbt-plugins")

View File

@ -0,0 +1 @@
> check