Skip to content

Commit

Permalink
Classifier/Type handling (#20)
Browse files Browse the repository at this point in the history
* Fixed classifier missing in final pom (#16)

* Fix classifier (#19)

* Fixed classifier missing in final pom

* Add artifact extension in pom file
  • Loading branch information
Federico Monti authored and skymontif committed Aug 5, 2019
1 parent 3a338e5 commit 3ec7c8b
Showing 1 changed file with 37 additions and 17 deletions.
54 changes: 37 additions & 17 deletions artifact-pom-manager.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,50 @@ def addDependencies(pom) {
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies

final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
dependencyNode.appendNode('scope', scope)
if (!dep.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('artifactId', '*')
exclusionNode.appendNode('groupId', '*')
} else if (!dep.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
final exclusionsNode = dependencyNode.appendNode('exclusions')
dep.properties.excludeRules.each { ExcludeRule rule ->
final exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
exclusionNode.appendNode('groupId', rule.group ?: '*')
if (dep.artifacts.size() > 0) {
dep.artifacts.each { art ->
addDependencyNode(dependenciesNode, dep, scope, art.classifier, art.extension)
}
} else {
addDependencyNode(dependenciesNode, dep, scope, null, null)
}
}
manageConfigurations(configurations)
}
}

def addDependencyNode(dependenciesNode, dep, scope, classifier, extension) {
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)

if (classifier != null) {
dependencyNode.appendNode('classifier', classifier)
}

if (extension != null) {
dependencyNode.appendNode('type', extension)
}

dependencyNode.appendNode('scope', scope)

if (!dep.transitive) {
// If this dependency is transitive, we should force exclude all its dependencies them from the POM
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('artifactId', '*')
exclusionNode.appendNode('groupId', '*')
} else if (!dep.properties.excludeRules.empty) {
// Otherwise add specified exclude rules
final exclusionsNode = dependencyNode.appendNode('exclusions')
dep.properties.excludeRules.each { ExcludeRule rule ->
final exclusionNode = exclusionsNode.appendNode('exclusion')
exclusionNode.appendNode('artifactId', rule.module ?: '*')
exclusionNode.appendNode('groupId', rule.group ?: '*')
}
}
}

def manageConfigurations(configurations) {
configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }
configurations.api.getDependencies().each { dep -> addDependency(dep, "compile") }
Expand Down

0 comments on commit 3ec7c8b

Please sign in to comment.