Add warning to MakePom for intransitive dependencies.

Intransitive does not work in Maven, and does not translate to pom.xml.
This commit is contained in:
Josh Suereth 2015-07-24 10:42:49 -04:00
parent efa6041103
commit 9beff22d9a
3 changed files with 41 additions and 16 deletions

View File

@ -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] =

View File

@ -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

View File

@ -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 <type> 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 <type> sections, got: " + tpe + " in \n\n" + pom)
if(tpe.nonEmpty) {
sys.error("Expected no <type> 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")}")
}