-
Notifications
You must be signed in to change notification settings - Fork 39
/
artifact-pom-manager.gradle
108 lines (93 loc) · 4 KB
/
artifact-pom-manager.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
def gradlePluginVersion = project.hasProperty('mavPluginVersion') ? project.mavPluginVersion : 'master'
apply from: "https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/${gradlePluginVersion}/utils.gradle"
def decoratePom(pom) {
pom.name = getStringProperty("mavProjectName")
pom.description = getStringProperty("mavLibraryDescription")
pom.url = getStringProperty("mavSiteUrl")
pom.licenses {
getArrayProperty("mavLibraryLicenses").each { licenseName, licenseUrl ->
license {
name = licenseName
url = licenseUrl
}
}
}
pom.developers {
getArrayProperty("mavDevelopers").each { developerId, developerName ->
developer {
id = developerId
name = developerName
}
}
}
pom.scm {
connection = getStringProperty("mavGitUrl")
developerConnection = getStringProperty("mavGitUrl")
url = getStringProperty("mavSiteUrl")
}
addDependencies(pom)
}
def addDependencies(pom) {
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep, String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies
if (dep.artifacts.size() > 0) {
dep.artifacts.each { art ->
addDependencyNode(dependenciesNode, dep, scope, art.archiveClassifier, art.extension)
}
} else {
addDependencyNode(dependenciesNode, dep, scope, null, null)
}
}
manageConfigurations(configurations)
}
}
def addDependencyNode(dependenciesNode, dep, scope, archiveClassifier, extension) {
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)
if (archiveClassifier != null) {
dependencyNode.appendNode('archiveClassifier', archiveClassifier)
}
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.api.getDependencies().each { dep -> addDependency(dep, "api") }
configurations.implementation.getDependencies().each { dep -> addDependency(dep, "implementation") }
configurations.testImplementation.getDependencies().each { dep -> addDependency(dep, "test") }
if (!isAndroidProject()) {
try {
configurations.runtime.getDependencies().each { dep -> addDependency(dep, "runtime") }
} catch (Exception ex) {
configurations.runtimeClasspath.getDependencies().each { dep -> addDependency(dep, "runtime") }
}
try {
configurations.testRuntime.getDependencies().each { dep -> addDependency(dep, "test") }
} catch (Exception ex) {
configurations.testRuntimeClasspath.getDependencies().each { dep -> addDependency(dep, "test") }
}
}
}
ext {
decoratePom = this.&decoratePom
}