From 9beff22d9a0a06eeea433530ddfed6c07e4ff412 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 24 Jul 2015 10:42:49 -0400 Subject: [PATCH] Add warning to MakePom for intransitive dependencies. Intransitive does not work in Maven, and does not translate to pom.xml. --- ivy/src/main/scala/sbt/MakePom.scala | 37 ++++++++++++------- .../0.13.10/warn-on-intransitive-pom.markdown | 9 +++++ .../dependency-management/pom-type/build.sbt | 11 +++++- 3 files changed, 41 insertions(+), 16 deletions(-) create mode 100644 notes/0.13.10/warn-on-intransitive-pom.markdown diff --git a/ivy/src/main/scala/sbt/MakePom.scala b/ivy/src/main/scala/sbt/MakePom.scala index 1dfa5d1fe..530070dda 100644 --- a/ivy/src/main/scala/sbt/MakePom.scala +++ b/ivy/src/main/scala/sbt/MakePom.scala @@ -236,21 +236,30 @@ class MakePom(val log: Logger) { def makeDependency(dependency: DependencyDescriptor, includeTypes: Set[String]): NodeSeq = makeDependency(dependency, includeTypes, Nil) - def makeDependency(dependency: DependencyDescriptor, includeTypes: Set[String], excludes: Seq[ExcludeRule]): NodeSeq = - { - val artifacts = dependency.getAllDependencyArtifacts - val includeArtifacts = artifacts.filter(d => includeTypes(d.getType)) - if (artifacts.isEmpty) { - val configs = dependency.getModuleConfigurations - if (configs.filterNot(Set("sources", "docs")).nonEmpty) { - val (scope, optional) = getScopeAndOptional(dependency.getModuleConfigurations) - makeDependencyElem(dependency, scope, optional, None, None, excludes) - } else NodeSeq.Empty - } else if (includeArtifacts.isEmpty) - NodeSeq.Empty - else - NodeSeq.fromSeq(artifacts.flatMap(a => makeDependencyElem(dependency, a, excludes))) + def makeDependency(dependency: DependencyDescriptor, includeTypes: Set[String], excludes: Seq[ExcludeRule]): NodeSeq = { + def warnIntransitve(): Unit = + if (!dependency.isTransitive) + log.warn( + s"""Translating intransitive dependency (${dependency.getDependencyId}) into pom.xml, but maven does not support intransitive dependencies. + | Please use exclusions instead so transitive dependencies will be correctly excluded in dependent projects. + """.stripMargin) + else () + val artifacts = dependency.getAllDependencyArtifacts + val includeArtifacts = artifacts.filter(d => includeTypes(d.getType)) + if (artifacts.isEmpty) { + val configs = dependency.getModuleConfigurations + if (configs.filterNot(Set("sources", "docs")).nonEmpty) { + warnIntransitve() + val (scope, optional) = getScopeAndOptional(dependency.getModuleConfigurations) + makeDependencyElem(dependency, scope, optional, None, None, excludes) + } else NodeSeq.Empty + } else if (includeArtifacts.isEmpty) { + NodeSeq.Empty + } else { + warnIntransitve() + NodeSeq.fromSeq(artifacts.flatMap(a => makeDependencyElem(dependency, a, excludes))) } + } @deprecated("Use `makeDependencyElem` variant which takes excludes", "0.13.9") def makeDependencyElem(dependency: DependencyDescriptor, artifact: DependencyArtifactDescriptor): Option[Elem] = diff --git a/notes/0.13.10/warn-on-intransitive-pom.markdown b/notes/0.13.10/warn-on-intransitive-pom.markdown new file mode 100644 index 000000000..686075531 --- /dev/null +++ b/notes/0.13.10/warn-on-intransitive-pom.markdown @@ -0,0 +1,9 @@ +[@jsuereth]: http://github.com/jsuereth + +### Fixes with compatibility implications + +### Improvements + +- makePom now warns when it sees intransitive dependencies, which do not translate to Maven. by [@jsuereth][@jsuereth] + +### Bug fixes diff --git a/sbt/src/sbt-test/dependency-management/pom-type/build.sbt b/sbt/src/sbt-test/dependency-management/pom-type/build.sbt index 899fa1aab..ca8287b37 100644 --- a/sbt/src/sbt-test/dependency-management/pom-type/build.sbt +++ b/sbt/src/sbt-test/dependency-management/pom-type/build.sbt @@ -1,6 +1,7 @@ scalaVersion := "2.10.2" libraryDependencies += "org.scala-sbt" %% "sbinary" % "0.4.1" withSources() withJavadoc() +libraryDependencies += "org.scala-sbt" % "io" % "0.13.8" intransitive() lazy val checkPom = taskKey[Unit]("check pom to ensure no sections are generated") @@ -8,6 +9,12 @@ checkPom := { val pomFile = makePom.value val pom = xml.XML.loadFile(pomFile) val tpe = pom \\ "type" - if(tpe.nonEmpty) - error("Expected no sections, got: " + tpe + " in \n\n" + pom) + if(tpe.nonEmpty) { + sys.error("Expected no sections, got: " + tpe + " in \n\n" + pom) + } + val dir = (streams in makePom).value.cacheDirectory / "out" + System.out.println(dir.getAbsolutePath) + val lines = IO.readLines(dir) + val hasError = lines exists { line => line contains "Translating intransitive dependency "} + assert(hasError, s"Failed to detect intransitive dependencies, got: ${lines.mkString("\n")}") } \ No newline at end of file