Add useJCenter setting, which is set to false. Fixes #2217

Adds a new setting `useJCenter`, which is set to `false` by default.
When set to `true`, JCenter will be placed as the first external
resolver to find library dependencies.

The implementation of `externalResolvers` is changed to incorporate the
setting by calling `Resolver.reorganizeAppResolvers`. These changes
were required because `externalResolvers` uses whatever that's in the
launchconfig, which the build user may not upgrade.
This commit is contained in:
Eugene Yokota 2015-12-25 23:20:56 -05:00
parent 6b3f6901af
commit c796c77386
6 changed files with 57 additions and 5 deletions

View File

@ -216,17 +216,44 @@ object Resolver {
/** Add the local and Maven Central repositories to the user repositories. */
def withDefaultResolvers(userResolvers: Seq[Resolver]): Seq[Resolver] =
withDefaultResolvers(userResolvers, true)
withDefaultResolvers(userResolvers, false, true)
/**
* Add the local Ivy repository to the user repositories.
* If `mavenCentral` is true, add the Maven Central repository.
*/
def withDefaultResolvers(userResolvers: Seq[Resolver], mavenCentral: Boolean): Seq[Resolver] =
withDefaultResolvers(userResolvers, false, mavenCentral)
/**
* Add the local Ivy repository to the user repositories.
* If `jcenter` is true, add the JCenter.
* If `mavenCentral` is true, add the Maven Central repository.
*/
private[sbt] def withDefaultResolvers(userResolvers: Seq[Resolver], jcenter: Boolean, mavenCentral: Boolean): Seq[Resolver] =
Seq(Resolver.defaultLocal) ++
userResolvers ++
single(JCenterRepository, jcenter) ++
single(DefaultMavenRepository, mavenCentral)
private def single[T](value: T, nonEmpty: Boolean): Seq[T] = if (nonEmpty) Seq(value) else Nil
/**
* Reorganize the built-in resolvers that is configured for this application by the sbt launcher.
* If `jcenter` is true, add the JCenter.
* If `mavenCentral` is true, add the Maven Central repository.
*/
private[sbt] def reorganizeAppResolvers(appResolvers: Seq[Resolver], jcenter: Boolean, mavenCentral: Boolean): Seq[Resolver] =
appResolvers.partition(_ == Resolver.defaultLocal) match {
case (locals, xs) =>
locals ++
(xs.partition(_ == JCenterRepository) match {
case (jc, xs) =>
single(JCenterRepository, jcenter) ++
(xs.partition(_ == DefaultMavenRepository) match {
case (m, xs) =>
single(DefaultMavenRepository, mavenCentral) ++ xs // TODO - Do we need to filter out duplicates?
})
})
}
/** A base class for defining factories for interfaces to Ivy repositories that require a hostname , port, and patterns. */
sealed abstract class Define[RepositoryType <: SshBasedRepository] extends NotNull {
/** Subclasses should implement this method to */

View File

@ -1110,6 +1110,7 @@ object Classpaths {
moduleConfigurations :== Nil,
publishTo :== None,
resolvers :== Nil,
useJCenter :== false,
retrievePattern :== Resolver.defaultRetrievePattern,
transitiveClassifiers :== Seq(SourceClassifier, DocClassifier),
sbtDependency := {
@ -1134,10 +1135,10 @@ object Classpaths {
organizationHomepage <<= organizationHomepage or homepage,
projectInfo <<= (name, description, homepage, startYear, licenses, organizationName, organizationHomepage, scmInfo, developers) apply ModuleInfo,
overrideBuildResolvers <<= appConfiguration(isOverrideRepositories),
externalResolvers <<= (externalResolvers.task.?, resolvers, appResolvers) {
case (Some(delegated), Seq(), _) => delegated
case (_, rs, Some(ars)) => task { ars ++ rs } // TODO - Do we need to filter out duplicates?
case (_, rs, _) => task { Resolver.withDefaultResolvers(rs) }
externalResolvers <<= (externalResolvers.task.?, resolvers, appResolvers, useJCenter) {
case (Some(delegated), Seq(), _, _) => delegated
case (_, rs, Some(ars), uj) => task { ars ++ Resolver.reorganizeAppResolvers(rs, uj, true) }
case (_, rs, _, uj) => task { Resolver.withDefaultResolvers(rs, uj) }
},
appResolvers <<= appConfiguration apply appRepositories,
bootResolvers <<= appConfiguration map bootRepositories,

View File

@ -298,6 +298,7 @@ object Keys {
val projectResolver = TaskKey[Resolver]("project-resolver", "Resolver that handles inter-project dependencies.", DTask)
val fullResolvers = TaskKey[Seq[Resolver]]("full-resolvers", "Combines the project resolver, default resolvers, and user-defined resolvers.", CTask)
val otherResolvers = SettingKey[Seq[Resolver]]("other-resolvers", "Resolvers not included in the main resolver chain, such as those in module configurations.", CSetting)
val useJCenter = SettingKey[Boolean]("use-jcenter", "Use JCenter as the default repository.", BSetting)
val moduleConfigurations = SettingKey[Seq[ModuleConfiguration]]("module-configurations", "Defines module configurations, which override resolvers on a per-module basis.", BMinusSetting)
val retrievePattern = SettingKey[String]("retrieve-pattern", "Pattern used to retrieve managed dependencies to the current build.", DSetting)
val retrieveConfiguration = SettingKey[Option[RetrieveConfiguration]]("retrieve-configuration", "Configures retrieving dependencies to the current build.", DSetting)

View File

@ -62,9 +62,11 @@
[1968]: https://github.com/sbt/sbt/issues/1968
[2264]: https://github.com/sbt/sbt/issues/2264
[2172]: https://github.com/sbt/sbt/pull/2172
[2217]: https://github.com/sbt/sbt/issues/2217
### Fixes with compatibility implications
- sbt 0.13.10 adds a new setting `useJCenter`, which is set to `false` by default. When set to `true`, JCenter will be placed as the first external resolver to find library dependencies. [#2217][2217] by [@eed3si9n][@eed3si9n]
- sbt will no longer pass `-J<flag>` options to the local Java compiler. [#1968][1968]/[#2272][2272] by [@Duhemm][@Duhemm]
### Improvements

View File

@ -0,0 +1,16 @@
lazy val check = taskKey[Unit]("")
lazy val check2 = taskKey[Unit]("")
lazy val root = (project in file(".")).
settings(
check := {
val fr = fullResolvers.value
assert(!(fr exists { _.name == "jcenter" }))
assert(fr exists { _.name == "public" })
},
check2 := {
val fr = fullResolvers.value
assert(fr exists { _.name == "jcenter" })
assert(fr exists { _.name == "public" })
}
)

View File

@ -0,0 +1,5 @@
> check
> set useJCenter := true
> check2