mirror of https://github.com/sbt/sbt.git
Add sbt-shading excludeDependencies test
This commit is contained in:
parent
bf34774e61
commit
e6a2d23524
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
enablePlugins(coursier.ShadingPlugin)
|
||||
shadingNamespace := "test.shaded"
|
||||
shadeNamespaces += "argonaut"
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"com.github.alexarchambault" %% "argonaut-shapeless_6.2" % "1.2.0-M5" % "shaded",
|
||||
// directly depending on that one for it not to be shaded
|
||||
"org.scala-lang" % "scala-reflect" % scalaVersion.value
|
||||
)
|
||||
|
||||
excludeDependencies += SbtExclusionRule("com.chuusai", "shapeless_2.11")
|
||||
|
||||
scalaVersion := "2.11.8"
|
||||
organization := "io.get-coursier.test"
|
||||
name := "shading-exclude-dependencies"
|
||||
version := "0.1.0-SNAPSHOT"
|
||||
Binary file not shown.
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
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-shading" % pluginVersion)
|
||||
}
|
||||
|
||||
// for the locally publish jarjar
|
||||
resolvers += Resolver.mavenLocal
|
||||
|
||||
val coursierJarjarVersion = "1.0.1-coursier-SNAPSHOT"
|
||||
|
||||
def coursierJarjarFoundInM2 =
|
||||
(file(sys.props("user.home")) / s".m2/repository/org/anarres/jarjar/jarjar-core/$coursierJarjarVersion").exists()
|
||||
|
||||
def jarjarVersion =
|
||||
if (coursierJarjarFoundInM2)
|
||||
coursierJarjarVersion
|
||||
else
|
||||
sys.error(
|
||||
"Ad hoc jarjar version not found. Run\n" +
|
||||
" git clone https://github.com/alexarchambault/jarjar.git && cd jarjar && git checkout 249c8dbb970f8 && ./gradlew install\n" +
|
||||
"to run this test"
|
||||
)
|
||||
|
||||
libraryDependencies += "org.anarres.jarjar" % "jarjar-core" % jarjarVersion
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
|
||||
import argonaut._
|
||||
|
||||
object Main extends App {
|
||||
|
||||
def excludeCheck(): Unit = {
|
||||
val className = "shapeless.HList"
|
||||
val loader = Thread.currentThread.getContextClassLoader
|
||||
|
||||
val found =
|
||||
try {
|
||||
loader.loadClass(className)
|
||||
true
|
||||
} catch {
|
||||
case _: java.lang.ClassNotFoundException => false
|
||||
}
|
||||
|
||||
assert(!found, s"Expected class $className not to be found")
|
||||
}
|
||||
|
||||
excludeCheck()
|
||||
|
||||
val expectedClassName =
|
||||
if (args.contains("--shaded"))
|
||||
"test.shaded.argonaut.Json"
|
||||
else
|
||||
// Don't use the literal "argonaut.Json", that seems to get
|
||||
// changed to "test.shaded.argonaut.Json" by shading
|
||||
"argonaut" + '.' + "Json"
|
||||
|
||||
val className = classOf[Json].getName
|
||||
|
||||
Console.err.println(s"Expected class name: $expectedClassName")
|
||||
Console.err.println(s"Class name: $className")
|
||||
|
||||
if (className != expectedClassName)
|
||||
sys.error(s"Expected class name $expectedClassName, got $className")
|
||||
|
||||
val msg = Json.obj().nospaces
|
||||
|
||||
Files.write(new File("output").toPath, msg.getBytes("UTF-8"))
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
$ delete output
|
||||
> run
|
||||
$ exists output
|
||||
> publishLocal
|
||||
$ exec java -jar coursier launch io.get-coursier.test:shading-exclude-dependencies_2.11:0.1.0-SNAPSHOT
|
||||
-$ exec java -jar coursier launch io.get-coursier.test:shading-exclude-dependencies_2.11:0.1.0-SNAPSHOT -- --shaded
|
||||
> shading:publishLocal
|
||||
-$ exec java -jar coursier launch io.get-coursier.test:shading-exclude-dependencies_2.11:0.1.0-SNAPSHOT
|
||||
$ exec java -jar coursier launch io.get-coursier.test:shading-exclude-dependencies_2.11:0.1.0-SNAPSHOT -- --shaded
|
||||
Loading…
Reference in New Issue