Set default artifact type to JAR from sbt plugin

Even if the packaging attribute of the dependency says the packaging is different (e.g. pom), this makes the plugin try to get a JAR anyway.

Fixes https://github.com/alexarchambault/coursier/issues/278
This commit is contained in:
Alexandre Archambault 2016-06-25 20:15:09 +02:00
parent 462c16d6db
commit 75c86690d5
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
8 changed files with 60 additions and 11 deletions

View File

@ -12,6 +12,7 @@ object CoursierPlugin extends AutoPlugin {
object autoImport { object autoImport {
val coursierParallelDownloads = Keys.coursierParallelDownloads val coursierParallelDownloads = Keys.coursierParallelDownloads
val coursierMaxIterations = Keys.coursierMaxIterations val coursierMaxIterations = Keys.coursierMaxIterations
val coursierDefaultArtifactType = Keys.coursierDefaultArtifactType
val coursierChecksums = Keys.coursierChecksums val coursierChecksums = Keys.coursierChecksums
val coursierArtifactsChecksums = Keys.coursierArtifactsChecksums val coursierArtifactsChecksums = Keys.coursierArtifactsChecksums
val coursierCachePolicies = Keys.coursierCachePolicies val coursierCachePolicies = Keys.coursierCachePolicies
@ -57,6 +58,7 @@ object CoursierPlugin extends AutoPlugin {
override lazy val projectSettings = Seq( override lazy val projectSettings = Seq(
coursierParallelDownloads := 6, coursierParallelDownloads := 6,
coursierMaxIterations := 50, coursierMaxIterations := 50,
coursierDefaultArtifactType := "jar",
coursierChecksums := Seq(Some("SHA-1"), None), coursierChecksums := Seq(Some("SHA-1"), None),
coursierArtifactsChecksums := Seq(None), coursierArtifactsChecksums := Seq(None),
coursierCachePolicies := CachePolicy.default, coursierCachePolicies := CachePolicy.default,

View File

@ -52,7 +52,8 @@ object FromSbt {
def dependencies( def dependencies(
module: ModuleID, module: ModuleID,
scalaVersion: String, scalaVersion: String,
scalaBinaryVersion: String scalaBinaryVersion: String,
defaultArtifactType: String
): Seq[(String, Dependency)] = { ): Seq[(String, Dependency)] = {
// TODO Warn about unsupported properties in `module` // TODO Warn about unsupported properties in `module`
@ -74,7 +75,7 @@ object FromSbt {
val attributes = val attributes =
if (module.explicitArtifacts.isEmpty) if (module.explicitArtifacts.isEmpty)
Seq(Attributes()) Seq(Attributes(defaultArtifactType, ""))
else else
module.explicitArtifacts.map { a => module.explicitArtifacts.map { a =>
Attributes(`type` = a.extension, classifier = a.classifier.getOrElse("")) Attributes(`type` = a.extension, classifier = a.classifier.getOrElse(""))
@ -105,14 +106,15 @@ object FromSbt {
allDependencies: Seq[ModuleID], allDependencies: Seq[ModuleID],
ivyConfigurations: Map[String, Seq[String]], ivyConfigurations: Map[String, Seq[String]],
scalaVersion: String, scalaVersion: String,
scalaBinaryVersion: String scalaBinaryVersion: String,
defaultArtifactType: String
): Project = { ): Project = {
// FIXME Ignored for now - easy to support though // FIXME Ignored for now - easy to support though
// val sbtDepOverrides = dependencyOverrides.value // val sbtDepOverrides = dependencyOverrides.value
// val sbtExclusions = excludeDependencies.value // val sbtExclusions = excludeDependencies.value
val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion)) val deps = allDependencies.flatMap(dependencies(_, scalaVersion, scalaBinaryVersion, defaultArtifactType))
Project( Project(
Module( Module(

View File

@ -12,6 +12,7 @@ import scala.concurrent.duration.Duration
object Keys { object Keys {
val coursierParallelDownloads = SettingKey[Int]("coursier-parallel-downloads") val coursierParallelDownloads = SettingKey[Int]("coursier-parallel-downloads")
val coursierMaxIterations = SettingKey[Int]("coursier-max-iterations") val coursierMaxIterations = SettingKey[Int]("coursier-max-iterations")
val coursierDefaultArtifactType = SettingKey[String]("coursier-default-artifact-type")
val coursierChecksums = SettingKey[Seq[Option[String]]]("coursier-checksums") val coursierChecksums = SettingKey[Seq[Option[String]]]("coursier-checksums")
val coursierArtifactsChecksums = SettingKey[Seq[Option[String]]]("coursier-artifacts-checksums") val coursierArtifactsChecksums = SettingKey[Seq[Option[String]]]("coursier-artifacts-checksums")
val coursierCachePolicies = SettingKey[Seq[CachePolicy]]("coursier-cache-policies") val coursierCachePolicies = SettingKey[Seq[CachePolicy]]("coursier-cache-policies")

View File

@ -76,16 +76,22 @@ object Tasks {
val allDependenciesTask = allDependencies.in(projectRef).get(state) val allDependenciesTask = allDependencies.in(projectRef).get(state)
lazy val projId = projectID.in(projectRef).get(state)
lazy val sv = scalaVersion.in(projectRef).get(state)
lazy val sbv = scalaBinaryVersion.in(projectRef).get(state)
lazy val defaultArtifactType = coursierDefaultArtifactType.in(projectRef).get(state)
for { for {
allDependencies <- allDependenciesTask allDependencies <- allDependenciesTask
} yield { } yield {
FromSbt.project( FromSbt.project(
projectID.in(projectRef).get(state), projId,
allDependencies, allDependencies,
configurations.map { cfg => cfg.name -> cfg.extendsConfigs.map(_.name) }.toMap, configurations.map { cfg => cfg.name -> cfg.extendsConfigs.map(_.name) }.toMap,
scalaVersion.in(projectRef).get(state), sv,
scalaBinaryVersion.in(projectRef).get(state) sbv,
defaultArtifactType
) )
} }
} }
@ -240,13 +246,15 @@ object Tasks {
if (sbtClassifiers) { if (sbtClassifiers) {
val sv = scalaVersion.value val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value val sbv = scalaBinaryVersion.value
val defaultArtifactType = coursierDefaultArtifactType.value
val proj = FromSbt.project( val proj = FromSbt.project(
cm.id, cm.id,
cm.modules, cm.modules,
cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap, cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap,
sv, sv,
sbv sbv,
defaultArtifactType
) )
val fallbackDeps = FromSbt.fallbackDependencies( val fallbackDeps = FromSbt.fallbackDependencies(
@ -587,13 +595,15 @@ object Tasks {
if (sbtClassifiers) { if (sbtClassifiers) {
val sv = scalaVersion.value val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value val sbv = scalaBinaryVersion.value
val defaultArtifactType = coursierDefaultArtifactType.value
FromSbt.project( FromSbt.project(
cm.id, cm.id,
cm.modules, cm.modules,
cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap, cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap,
sv, sv,
sbv sbv,
defaultArtifactType
) )
} else { } else {
val proj = coursierProject.value val proj = coursierProject.value
@ -800,13 +810,15 @@ object Tasks {
val cm = coursierSbtClassifiersModule.value val cm = coursierSbtClassifiersModule.value
val sv = scalaVersion.value val sv = scalaVersion.value
val sbv = scalaBinaryVersion.value val sbv = scalaBinaryVersion.value
val defaultArtifactType = coursierDefaultArtifactType.value
FromSbt.project( FromSbt.project(
cm.id, cm.id,
cm.modules, cm.modules,
cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap, cm.configurations.map(cfg => cfg.name -> cfg.extendsConfigs.map(_.name)).toMap,
sv, sv,
sbv sbv,
defaultArtifactType
) )
} else { } else {
val proj = coursierProject.value val proj = coursierProject.value

View File

@ -0,0 +1,10 @@
scalaVersion := "2.11.8"
libraryDependencies += "org.apache.zookeeper" % "zookeeper" % "3.5.0-alpha"
coursierCachePolicies := {
if (sys.props("os.name").startsWith("Windows"))
coursierCachePolicies.value
else
Seq(coursier.CachePolicy.ForceDownload)
}

View File

@ -0,0 +1,11 @@
{
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)
addSbtPlugin("io.get-coursier" % "sbt-coursier" % pluginVersion)
}

View File

@ -0,0 +1,8 @@
import java.io.File
import java.nio.file.Files
import org.apache.zookeeper.ZooKeeper
object Main extends App {
Files.write(new File("output").toPath, classOf[ZooKeeper].getSimpleName.getBytes("UTF-8"))
}

View File

@ -0,0 +1,3 @@
$ delete output
> run
$ exists output