From 3ea2f33358384531bbed65ed507077d5eed41131 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Wed, 10 Jan 2018 10:27:45 -0800 Subject: [PATCH] #67: Do not add dependencies of aggregated projects --- build.sbt | 2 +- src/main/scala/xerial/sbt/pack/PackPlugin.scala | 11 ++++++----- src/sbt-test/sbt-pack/archive-modules/build.sbt | 3 ++- src/sbt-test/sbt-pack/archive-modules/test | 7 +++---- src/sbt-test/sbt-pack/copy-dependencies/build.sbt | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/build.sbt b/build.sbt index 77332d48..d1e60b3e 100644 --- a/build.sbt +++ b/build.sbt @@ -15,7 +15,7 @@ pomIncludeRepository := { _ => } sbtPlugin := true -crossSbtVersions := Vector("1.0.4", "0.13.16") +crossSbtVersions := Vector("1.1.0", "0.13.16") scalaVersion in ThisBuild := "2.12.4" diff --git a/src/main/scala/xerial/sbt/pack/PackPlugin.scala b/src/main/scala/xerial/sbt/pack/PackPlugin.scala index 96481831..86d43be5 100755 --- a/src/main/scala/xerial/sbt/pack/PackPlugin.scala +++ b/src/main/scala/xerial/sbt/pack/PackPlugin.scala @@ -219,7 +219,7 @@ object PackPlugin extends AutoPlugin with PackArchive { libDir.mkdirs() // Copy project jars - val base: File = baseDirectory.value + val base: File = new File(".") // Using the working directory as base for readability out.log.info("Copying libraries to " + rpath(base, libDir)) val libs: Seq[File] = packLibJars.value.map(_._1) out.log.info("project jars:\n" + libs.map(path => rpath(base, path)).mkString("\n")) @@ -407,13 +407,14 @@ object PackPlugin extends AutoPlugin with PackArchive { val extracted = Project.extract(state) val structure = extracted.structure - def allProjectRefs(currentProject: ProjectRef): Seq[ProjectRef] = { + def transitiveDependencies(currentProject: ProjectRef): Seq[ProjectRef] = { def isExcluded(p: ProjectRef) = exclude.contains(p.project) - val children = Project.getProject(currentProject, structure).toSeq.flatMap(_.uses) - (currentProject +: (children flatMap (allProjectRefs(_)))) filterNot (isExcluded) + // Traverse all dependent projects + val children = Project.getProject(currentProject, structure).toSeq.flatMap(_.dependencies.map(_.project)) + (currentProject +: (children flatMap (transitiveDependencies(_)))) filterNot (isExcluded) } - val projects: Seq[ProjectRef] = allProjectRefs(extracted.currentRef).distinct + val projects: Seq[ProjectRef] = transitiveDependencies(extracted.currentRef).distinct projects.map(p => (Def.task { ((targetTask in p).value, p) }) evaluate structure.data).join } diff --git a/src/sbt-test/sbt-pack/archive-modules/build.sbt b/src/sbt-test/sbt-pack/archive-modules/build.sbt index 5e164a60..59b9ad58 100644 --- a/src/sbt-test/sbt-pack/archive-modules/build.sbt +++ b/src/sbt-test/sbt-pack/archive-modules/build.sbt @@ -15,7 +15,8 @@ lazy val root = ).enablePlugins(PackPlugin) .settings(commonSettings) .settings(publishPackArchives) - .aggregate(module1, module2) + .aggregate(module1, module2) // dependency of module2 should not be included + .dependsOn(module1) lazy val module1 = Project( id = "module1", diff --git a/src/sbt-test/sbt-pack/archive-modules/test b/src/sbt-test/sbt-pack/archive-modules/test index b2040fa2..7bc5f75b 100644 --- a/src/sbt-test/sbt-pack/archive-modules/test +++ b/src/sbt-test/sbt-pack/archive-modules/test @@ -4,12 +4,11 @@ $ exists target/archive-modules-0.1.tar.gz $ exists target/archive-modules-0.1.zip $ exists target/pack/bin/module1 $ exec sh ./target/pack/bin/module1 -$ exists target/pack/bin/module2 -$ exec sh ./target/pack/bin/module2 +$ absent target/pack/bin/module2 $ exists module2/target/module2-0.1.tar.gz $ exists module2/target/module2-0.1.zip -$ exists module2/target/pack/bin/module2 -$ exec sh ./module2/target/pack/bin/module2 +$ absent module2/target/pack/bin/module2 +$ absent target/pack/lib/snappy-java-1.1.1.6.jar $ exists module1/target/module1-0.1.tar.gz $ exists module1/target/module1-0.1.zip $ exists module1/target/pack/bin/module1 diff --git a/src/sbt-test/sbt-pack/copy-dependencies/build.sbt b/src/sbt-test/sbt-pack/copy-dependencies/build.sbt index 304be996..16e15c1b 100644 --- a/src/sbt-test/sbt-pack/copy-dependencies/build.sbt +++ b/src/sbt-test/sbt-pack/copy-dependencies/build.sbt @@ -12,7 +12,7 @@ lazy val root = (project in file(".")) // custom settings here ): _* ).enablePlugins(PackPlugin) - .aggregate(module1, module2, module3, module4) + .dependsOn(module1, module2, module3, module4) lazy val module1 = project .settings(