Merge pull request #5930 from adpi2/bsp-custom-config

fix BSP on custom configs
This commit is contained in:
eugene yokota 2020-10-05 15:27:40 -04:00 committed by GitHub
commit 536da2f29c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 6 deletions

View File

@ -577,11 +577,22 @@ object BuildServerProtocol {
} }
private def internalDependencyConfigurationsSetting = Def.settingDyn { private def internalDependencyConfigurationsSetting = Def.settingDyn {
val directDependencies = Keys.internalDependencyConfigurations.value.map { val allScopes = bspWorkspace.value.map { case (_, scope) => scope }.toSet
case (project, rawConfigs) => val directDependencies = Keys.internalDependencyConfigurations.value
val configs = rawConfigs.flatMap(_.split(",")).map(name => ConfigKey(name.trim)) .map {
(project, configs) case (project, rawConfigs) =>
} val configs = rawConfigs
.flatMap(_.split(","))
.map(name => ConfigKey(name.trim))
.filter { config =>
val scope = Scope.Global.in(project, config)
allScopes.contains(scope)
}
(project, configs)
}
.filter {
case (_, configs) => configs.nonEmpty
}
val ref = Keys.thisProjectRef.value val ref = Keys.thisProjectRef.value
val thisConfig = Keys.configuration.value val thisConfig = Keys.configuration.value
val transitiveDependencies = for { val transitiveDependencies = for {
@ -589,7 +600,8 @@ object BuildServerProtocol {
config <- configs if dep != ref || config.name != thisConfig.name config <- configs if dep != ref || config.name != thisConfig.name
} yield Keys.bspInternalDependencyConfigurations.in(dep, config) } yield Keys.bspInternalDependencyConfigurations.in(dep, config)
Def.setting { Def.setting {
val allDependencies = directDependencies ++ transitiveDependencies.join.value.flatten val allDependencies = directDependencies ++
transitiveDependencies.join.value.flatten
allDependencies allDependencies
.groupBy(_._1) .groupBy(_._1)
.mapValues { deps => .mapValues { deps =>

View File

@ -0,0 +1,49 @@
// Custom configurations
lazy val Common = config("common").describedAs("Dependencies required in all configurations.")
lazy val Scalate = config("scalate").extend(Common).describedAs("Dependencies for using Scalate utilities.")
lazy val Saxon = config("saxon").extend(Common).describedAs("Dependencies for using Saxon utilities.")
// Define a customized compile configuration that includes
// dependencies defined in our other custom configurations
lazy val CustomCompile = config("compile").extend(Saxon, Common, Scalate)
// factor out common settings
ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.10.6"
ThisBuild / version := "0.1.0-SNAPSHOT"
// An example project that only uses the Scalate utilities.
lazy val a = (project in file("a"))
.dependsOn(utils % "compile->scalate")
// An example project that uses the Scalate and Saxon utilities.
// For the configurations defined here, this is equivalent to doing dependsOn(utils),
// but if there were more configurations, it would select only the Scalate and Saxon
// dependencies.
lazy val b = (project in file("b"))
.dependsOn(utils % "compile->scalate,saxon")
// Defines the utilities project
lazy val utils = (project in file("utils"))
.settings(
inConfig(Common)(Defaults.configSettings), // Add the src/common/scala/ compilation configuration.
addArtifact(Common / packageBin / artifact, Common / packageBin), // Publish the common artifact
// We want our Common sources to have access to all of the dependencies on the classpaths
// for compile and test, but when depended on, it should only require dependencies in 'common'
Common / classpathConfiguration := CustomCompile,
// Modify the default Ivy configurations.
// 'overrideConfigs' ensures that Compile is replaced by CustomCompile
ivyConfigurations := overrideConfigs(Scalate, Saxon, Common, CustomCompile)(ivyConfigurations.value),
// Put all dependencies without an explicit configuration into Common (optional)
defaultConfiguration := Some(Common),
// Declare dependencies in the appropriate configurations
libraryDependencies ++= Seq(
"org.fusesource.scalate" % "scalate-core" % "1.5.0" % Scalate,
"org.squeryl" %% "squeryl" % "0.9.5-6" % Scalate,
"net.sf.saxon" % "saxon" % "8.7" % Saxon
)
)

View File

@ -0,0 +1 @@
> name