From 2420fa8a6988d14496e629e680441a8102b905b9 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Thu, 6 Apr 2017 00:14:33 +0200 Subject: [PATCH] Tweak optional pseudo-configuration Have it ~extends "default" rather than "compile", so that depending on both "default" and "optional" can be simplified to just "optional" ("default" being pulled by it now, thanks to this change). That allows to address the scala-compiler jar appearing twice on the classpath sometimes. --- .../main/scala/coursier/core/Resolution.scala | 2 +- .../coursier/maven/MavenRepository.scala | 2 +- .../scala/coursier/test/CentralTests.scala | 37 ++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/core/shared/src/main/scala/coursier/core/Resolution.scala b/core/shared/src/main/scala/coursier/core/Resolution.scala index 511d7c8e2..e023ae45d 100644 --- a/core/shared/src/main/scala/coursier/core/Resolution.scala +++ b/core/shared/src/main/scala/coursier/core/Resolution.scala @@ -351,7 +351,7 @@ object Resolution { private val mavenScopes = { val base = Map[String, Set[String]]( "compile" -> Set("compile"), - "optional" -> Set("compile", "optional"), + "optional" -> Set("compile", "optional", "runtime"), "provided" -> Set(), "runtime" -> Set("compile", "runtime"), "test" -> Set() diff --git a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala index b28ddfbb0..d92d0b45a 100644 --- a/core/shared/src/main/scala/coursier/maven/MavenRepository.scala +++ b/core/shared/src/main/scala/coursier/maven/MavenRepository.scala @@ -330,7 +330,7 @@ final case class MavenRepository( val proj = Pom.addOptionalDependenciesInConfig( proj0.copy(configurations = defaultConfigurations), - Set("", "compile"), + Set("", "default"), "optional" ) diff --git a/tests/shared/src/test/scala/coursier/test/CentralTests.scala b/tests/shared/src/test/scala/coursier/test/CentralTests.scala index 710d609e7..4a6765218 100644 --- a/tests/shared/src/test/scala/coursier/test/CentralTests.scala +++ b/tests/shared/src/test/scala/coursier/test/CentralTests.scala @@ -135,8 +135,17 @@ object CentralTests extends TestSuite { extraRepo: Option[Repository] )( f: Seq[Artifact] => T + ): Future[T] = + withArtifacts(Set(dep), artifactType, extraRepo)(f) + + def withArtifacts[T]( + deps: Set[Dependency], + artifactType: String, + extraRepo: Option[Repository] + )( + f: Seq[Artifact] => T ): Future[T] = async { - val res = await(resolve(Set(dep), extraRepo = extraRepo)) + val res = await(resolve(deps, extraRepo = extraRepo)) assert(res.errors.isEmpty) assert(res.conflicts.isEmpty) @@ -348,6 +357,32 @@ object CentralTests extends TestSuite { 'runtime - check("runtime") } + 'optionalScope - { + + def intransitiveCompiler(config: String) = + Dependency( + Module("org.scala-lang", "scala-compiler"), "2.11.8", + configuration = config, + transitive = false + ) + + withArtifacts( + Set( + intransitiveCompiler("default"), + intransitiveCompiler("optional") + ), + "jar", + None + ) { + case Seq() => + throw new Exception("Expected one JAR") + case Seq(jar) => + () // ok + case other => + throw new Exception(s"Got too many JARs (${other.mkString})") + } + } + 'packaging - { 'aar - { // random aar-based module found on Central