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