Do not emit in the pom dependencies that are only sources or docs

The pom generation code tries its best to map Ivy's configurations
to Maven scopes; however, sources and javadoc artifacts cannot be
properly mapped and they currently are emitted as dependencies in
the default scope (compile). That may lead to the source/doc jars
being erroneously processed like regular jars by automated tools.

Arguably, the source/docs jars should not be included in the pom
file as dependencies at all. This commit filters out the
dependencies that only appear in the sources and/or javadoc Ivy
configurations, thereby preventing them from appearing in the
final pom file.
This commit is contained in:
Antonio Cunei 2015-05-20 03:26:30 +02:00
parent ed0423ee59
commit 65dc88adc6
1 changed files with 17 additions and 12 deletions

View File

@ -233,28 +233,33 @@ class MakePom(val log: Logger) {
val artifacts = dependency.getAllDependencyArtifacts
val includeArtifacts = artifacts.filter(d => includeTypes(d.getType))
if (artifacts.isEmpty) {
val (scope, optional) = getScopeAndOptional(dependency.getModuleConfigurations)
makeDependencyElem(dependency, scope, optional, None, None)
val configs = dependency.getModuleConfigurations
if (configs.filterNot(Set("sources","docs")).nonEmpty) {
val (scope, optional) = getScopeAndOptional(dependency.getModuleConfigurations)
makeDependencyElem(dependency, scope, optional, None, None)
} else NodeSeq.Empty
} else if (includeArtifacts.isEmpty)
NodeSeq.Empty
else
NodeSeq.fromSeq(artifacts.map(a => makeDependencyElem(dependency, a)))
NodeSeq.fromSeq(artifacts.flatMap(a => makeDependencyElem(dependency, a)))
}
def makeDependencyElem(dependency: DependencyDescriptor, artifact: DependencyArtifactDescriptor): Elem =
def makeDependencyElem(dependency: DependencyDescriptor, artifact: DependencyArtifactDescriptor): Option[Elem] =
{
val configs = artifact.getConfigurations.toList match {
case Nil | "*" :: Nil => dependency.getModuleConfigurations
case x => x.toArray
}
val (scope, optional) = getScopeAndOptional(configs)
val classifier = artifactClassifier(artifact)
val baseType = artifactType(artifact)
val tpe = (classifier, baseType) match {
case (Some(c), Some(tpe)) if Artifact.classifierType(c) == tpe => None
case _ => baseType
}
makeDependencyElem(dependency, scope, optional, classifier, tpe)
if (configs.filterNot(Set("sources","docs")).nonEmpty) {
val (scope, optional) = getScopeAndOptional(configs)
val classifier = artifactClassifier(artifact)
val baseType = artifactType(artifact)
val tpe = (classifier, baseType) match {
case (Some(c), Some(tpe)) if Artifact.classifierType(c) == tpe => None
case _ => baseType
}
Some(makeDependencyElem(dependency, scope, optional, classifier, tpe))
} else None
}
def makeDependencyElem(dependency: DependencyDescriptor, scope: Option[String], optional: Boolean, classifier: Option[String], tpe: Option[String]): Elem =
{