mirror of https://github.com/sbt/sbt.git
Better handling of optional dependencies
This commit is contained in:
parent
cce332eb55
commit
766ccbf5a9
|
|
@ -351,6 +351,7 @@ object Resolution {
|
||||||
private val mavenScopes = {
|
private val mavenScopes = {
|
||||||
val base = Map[String, Set[String]](
|
val base = Map[String, Set[String]](
|
||||||
"compile" -> Set("compile"),
|
"compile" -> Set("compile"),
|
||||||
|
"optional" -> Set("compile", "optional"),
|
||||||
"provided" -> Set(),
|
"provided" -> Set(),
|
||||||
"runtime" -> Set("compile", "runtime"),
|
"runtime" -> Set("compile", "runtime"),
|
||||||
"test" -> Set()
|
"test" -> Set()
|
||||||
|
|
@ -463,10 +464,16 @@ object Resolution {
|
||||||
default
|
default
|
||||||
else
|
else
|
||||||
keepOpt.fold(default) { keep =>
|
keepOpt.fold(default) { keep =>
|
||||||
if (keep(config))
|
if (keep(config)) {
|
||||||
// really keeping the from.configuration, with its fallback config part
|
val depConfig =
|
||||||
Seq(dep.copy(configuration = from.configuration))
|
if (actualConfig == "optional")
|
||||||
else
|
defaultConfiguration
|
||||||
|
else
|
||||||
|
// really keeping the from.configuration, with its fallback config part
|
||||||
|
from.configuration
|
||||||
|
|
||||||
|
Seq(dep.copy(configuration = depConfig))
|
||||||
|
} else
|
||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -287,12 +287,12 @@ final case class MavenRepository(
|
||||||
for {
|
for {
|
||||||
str <- fetch(projectArtifact(module, version, versioningValue))
|
str <- fetch(projectArtifact(module, version, versioningValue))
|
||||||
rawListFilesPage <- fetch(artifactFor(listFilesUrl))
|
rawListFilesPage <- fetch(artifactFor(listFilesUrl))
|
||||||
proj <- EitherT(F.point[String \/ Project](parseRawPom(str)))
|
proj0 <- EitherT(F.point[String \/ Project](parseRawPom(str)))
|
||||||
} yield {
|
} yield {
|
||||||
|
|
||||||
val files = WebPage.listFiles(listFilesUrl, rawListFilesPage)
|
val files = WebPage.listFiles(listFilesUrl, rawListFilesPage)
|
||||||
|
|
||||||
val versioning = proj
|
val versioning = proj0
|
||||||
.snapshotVersioning
|
.snapshotVersioning
|
||||||
.flatMap(versioning =>
|
.flatMap(versioning =>
|
||||||
mavenVersioning(versioning, "", "")
|
mavenVersioning(versioning, "", "")
|
||||||
|
|
@ -300,7 +300,7 @@ final case class MavenRepository(
|
||||||
|
|
||||||
val prefix = s"${module.name}-${versioning.getOrElse(version)}"
|
val prefix = s"${module.name}-${versioning.getOrElse(version)}"
|
||||||
|
|
||||||
val packagingTpeMap = proj.packagingOpt
|
val packagingTpeMap = proj0.packagingOpt
|
||||||
.map { packaging =>
|
.map { packaging =>
|
||||||
(MavenSource.typeDefaultClassifier(packaging), MavenSource.typeExtension(packaging)) -> packaging
|
(MavenSource.typeDefaultClassifier(packaging), MavenSource.typeExtension(packaging)) -> packaging
|
||||||
}
|
}
|
||||||
|
|
@ -323,9 +323,14 @@ final case class MavenRepository(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val proj = Pom.addOptionalDependenciesInConfig(
|
||||||
|
proj0.copy(configurations = defaultConfigurations),
|
||||||
|
Set("", "compile"),
|
||||||
|
"optional"
|
||||||
|
)
|
||||||
|
|
||||||
proj.copy(
|
proj.copy(
|
||||||
actualVersionOpt = Some(version),
|
actualVersionOpt = Some(version),
|
||||||
configurations = defaultConfigurations,
|
|
||||||
publications = foundPublications
|
publications = foundPublications
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -451,4 +451,24 @@ object Pom {
|
||||||
} yield modVers :+ modVer
|
} yield modVers :+ modVer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def addOptionalDependenciesInConfig(
|
||||||
|
proj: Project,
|
||||||
|
fromConfigs: Set[String],
|
||||||
|
optionalConfig: String
|
||||||
|
): Project = {
|
||||||
|
|
||||||
|
val optionalDeps = proj.dependencies.collect {
|
||||||
|
case (conf, dep) if dep.optional && fromConfigs(conf) =>
|
||||||
|
optionalConfig -> dep.copy(optional = false)
|
||||||
|
}
|
||||||
|
|
||||||
|
val configurations = proj.configurations +
|
||||||
|
(optionalConfig -> (proj.configurations.getOrElse(optionalConfig, Nil) ++ fromConfigs.filter(_.nonEmpty)).distinct)
|
||||||
|
|
||||||
|
proj.copy(
|
||||||
|
configurations = configurations,
|
||||||
|
dependencies = proj.dependencies ++ optionalDeps
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package coursier
|
package coursier
|
||||||
|
|
||||||
import java.io.{ OutputStreamWriter, File }
|
import java.io.{ File, InputStream, OutputStreamWriter }
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.concurrent.{ ExecutorService, Executors }
|
import java.util.concurrent.{ ExecutorService, Executors }
|
||||||
|
|
||||||
|
|
@ -123,10 +123,14 @@ object Tasks {
|
||||||
allDependencies <- allDependenciesTask
|
allDependencies <- allDependenciesTask
|
||||||
} yield {
|
} yield {
|
||||||
|
|
||||||
|
val configMap = configurations
|
||||||
|
.map { cfg => cfg.name -> cfg.extendsConfigs.map(_.name) }
|
||||||
|
.toMap
|
||||||
|
|
||||||
FromSbt.project(
|
FromSbt.project(
|
||||||
projId,
|
projId,
|
||||||
allDependencies,
|
allDependencies,
|
||||||
configurations.map { cfg => cfg.name -> cfg.extendsConfigs.map(_.name) }.toMap,
|
configMap,
|
||||||
sv,
|
sv,
|
||||||
sbv
|
sbv
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
org.scala-lang:scala-compiler:2.11.8:compile
|
||||||
|
org.scala-lang:scala-library:2.11.8:compile
|
||||||
|
org.scala-lang:scala-reflect:2.11.8:compile
|
||||||
|
org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4:compile
|
||||||
|
org.scala-lang.modules:scala-xml_2.11:1.0.4:compile
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
jline:jline:2.12.1:compile
|
||||||
|
org.scala-lang:scala-compiler:2.11.8:optional
|
||||||
|
org.scala-lang:scala-library:2.11.8:compile
|
||||||
|
org.scala-lang:scala-reflect:2.11.8:compile
|
||||||
|
org.scala-lang.modules:scala-parser-combinators_2.11:1.0.4:compile
|
||||||
|
org.scala-lang.modules:scala-xml_2.11:1.0.4:compile
|
||||||
|
|
@ -465,6 +465,22 @@ object CentralTests extends TestSuite {
|
||||||
"0.5.0"
|
"0.5.0"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
'scalaCompilerJLine - {
|
||||||
|
|
||||||
|
// optional should bring jline
|
||||||
|
|
||||||
|
* - resolutionCheck(
|
||||||
|
Module("org.scala-lang", "scala-compiler"),
|
||||||
|
"2.11.8"
|
||||||
|
)
|
||||||
|
|
||||||
|
* - resolutionCheck(
|
||||||
|
Module("org.scala-lang", "scala-compiler"),
|
||||||
|
"2.11.8",
|
||||||
|
configuration = "optional"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue