mirror of https://github.com/sbt/sbt.git
Publish test artifacts in Test configuration and corrects classifier to 'tests'. Fixes #683
This commit is contained in:
parent
56b85522b7
commit
718fa91772
|
|
@ -11,7 +11,7 @@ final case class Artifact(name: String, `type`: String, extension: String, class
|
|||
def extra(attributes: (String,String)*) = Artifact(name, `type`, extension, classifier, configurations, url, extraAttributes ++ ModuleID.checkE(attributes))
|
||||
}
|
||||
|
||||
import Configurations.{config, Docs, Optional, Pom, Sources}
|
||||
import Configurations.{config, Docs, Optional, Pom, Sources, Test}
|
||||
|
||||
object Artifact
|
||||
{
|
||||
|
|
@ -36,6 +36,7 @@ object Artifact
|
|||
val DocType = "doc"
|
||||
val SourceType = "src"
|
||||
val PomType = "pom"
|
||||
val TestsClassifier = "tests"
|
||||
|
||||
def extract(url: URL, default: String): String = extract(url.toString, default)
|
||||
def extract(name: String, default: String): String =
|
||||
|
|
@ -64,8 +65,12 @@ object Artifact
|
|||
|
||||
val classifierConfMap = Map(SourceClassifier -> Sources, DocClassifier -> Docs)
|
||||
val classifierTypeMap = Map(SourceClassifier -> SourceType, DocClassifier -> DocType)
|
||||
def classifierConf(classifier: String): Configuration = classifierConfMap.getOrElse(classifier, Optional)
|
||||
def classifierType(classifier: String): String = classifierTypeMap.getOrElse(classifier.stripPrefix("test-"), DefaultType)
|
||||
def classifierConf(classifier: String): Configuration =
|
||||
if(classifier.startsWith(TestsClassifier))
|
||||
Test
|
||||
else
|
||||
classifierConfMap.getOrElse(classifier, Optional)
|
||||
def classifierType(classifier: String): String = classifierTypeMap.getOrElse(classifier.stripPrefix(TestsClassifier + "-"), DefaultType)
|
||||
def classified(name: String, classifier: String): Artifact =
|
||||
Artifact(name, classifierType(classifier), DefaultExtension, Some(classifier), classifierConf(classifier) :: Nil, None)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -520,7 +520,11 @@ object Defaults extends BuildCommon
|
|||
t / toString(ScalaVersion(sv, sbv), module, a) asFile
|
||||
}
|
||||
def artifactSetting = ((artifact, artifactClassifier).identity zipWith configuration.?) { case ((a,classifier),cOpt) =>
|
||||
val cPart = cOpt flatMap { c => if(c == Compile) None else Some(c.name) }
|
||||
val cPart = cOpt flatMap {
|
||||
case Compile => None
|
||||
case Test => Some(Artifact.TestsClassifier)
|
||||
case c => Some(c.name)
|
||||
}
|
||||
val combined = cPart.toList ++ classifier.toList
|
||||
if(combined.isEmpty) a.copy(classifier = None, configurations = cOpt.toList) else {
|
||||
val classifierString = combined mkString "-"
|
||||
|
|
@ -529,13 +533,11 @@ object Defaults extends BuildCommon
|
|||
}
|
||||
}
|
||||
def artifactConfigurations(base: Artifact, scope: Configuration, classifier: Option[String]): Iterable[Configuration] =
|
||||
if(base.configurations.isEmpty)
|
||||
classifier match {
|
||||
case Some(c) => Artifact.classifierConf(c) :: Nil
|
||||
case None => scope :: Nil
|
||||
}
|
||||
else
|
||||
base.configurations
|
||||
classifier match {
|
||||
case Some(c) => Artifact.classifierConf(c) :: Nil
|
||||
case None => scope :: Nil
|
||||
}
|
||||
|
||||
@deprecated("Use `Util.pairID` instead", "0.12.0")
|
||||
def pairID = Util.pairID
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
object Use {
|
||||
val x = Def.x
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
ivyPaths := {
|
||||
val base = baseDirectory.value
|
||||
new IvyPaths(base, Some(base / "ivy-cache"))
|
||||
}
|
||||
|
||||
managedScalaInstance := false
|
||||
|
||||
autoScalaLibrary := false
|
||||
|
||||
crossPaths := false
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
public final class Def {
|
||||
public static final int x = 3;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
organization := "org.example"
|
||||
|
||||
name := "def"
|
||||
|
||||
version := "2.0"
|
||||
|
||||
publishTo := Some(Resolver.file("example", baseDirectory.value / "ivy-repo"))
|
||||
|
||||
publishArtifact in Test := true
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
public final class Use {
|
||||
public static final int x = Def.x;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
name := "use"
|
||||
|
||||
organization := "org.example"
|
||||
|
||||
version := "1.0"
|
||||
|
||||
libraryDependencies += "org.example" % "def" % "2.0"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
libraryDependencies += "org.example" % "def" % "2.0" % "compile->test"
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
libraryDependencies += "org.example" % "def" % "2.0" classifier("tests")
|
||||
|
||||
externalResolvers := Seq("example" at (baseDirectory.value / "ivy-repo").toURI.toString)
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# define a test jar and publish locally as ivy.xml
|
||||
# and to a file repository as pom.xml
|
||||
|
||||
$ copy-file changes/def/build.sbt build.sbt
|
||||
$ copy-file changes/def/Def.java src/test/java/Def.java
|
||||
> reload
|
||||
> publish-local
|
||||
> publish
|
||||
> clean
|
||||
|
||||
$ delete build.sbt
|
||||
$ delete src/test/java/Def.java
|
||||
|
||||
# use the test jar from the maven repository
|
||||
# by requesting the "tests" classifier
|
||||
|
||||
$ copy-file changes/use/build.sbt build.sbt
|
||||
$ copy-file changes/use/Use.java Use.java
|
||||
$ copy-file changes/use/pom.sbt pom.sbt
|
||||
> reload
|
||||
> compile
|
||||
> clean
|
||||
|
||||
# necessary because the cache can't deal with two different types of metadata
|
||||
$ delete ivy-cache/cache
|
||||
|
||||
|
||||
# then, use the test jar via the Ivy repository
|
||||
# by requesting the "test" configuration
|
||||
|
||||
$ delete pom.sbt
|
||||
$ copy-file changes/use/local.sbt local.sbt
|
||||
> reload
|
||||
> show update
|
||||
> export dependencyClasspath
|
||||
> compile
|
||||
Loading…
Reference in New Issue