Skip to content

Commit

Permalink
#67: Do not add dependencies of aggregated projects
Browse files Browse the repository at this point in the history
  • Loading branch information
xerial committed Jan 10, 2018
1 parent 512a7c4 commit 3ea2f33
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
11 changes: 6 additions & 5 deletions src/main/scala/xerial/sbt/pack/PackPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 2 additions & 1 deletion src/sbt-test/sbt-pack/archive-modules/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 3 additions & 4 deletions src/sbt-test/sbt-pack/archive-modules/test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-pack/copy-dependencies/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 3ea2f33

Please sign in to comment.