-
Notifications
You must be signed in to change notification settings - Fork 3
/
optional.gradle
55 lines (46 loc) · 1.48 KB
/
optional.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
// Extracted from Peter Niederwieser work in spockframework:
// https://github.com/spockframework/spock/blob/4916ace3cbb853193c65db312214dbdf66ce62ae/gradle/publishMaven.gradle
boolean matches(/*org.apache.maven.model.Dependency*/ mvn, org.gradle.api.artifacts.ModuleDependency dep) {
if (mvn.groupId != dep.group) {
return false
}
if (dep.artifacts.isEmpty()) {
return mvn.artifactId == dep.name
}
for (org.gradle.api.artifacts.DependencyArtifact art in dep.artifacts) {
if (mvn.artifactId == art.name) {
return true
}
}
false
}
def optionalDeps = []
def providedDeps = []
def internalDeps = []
project.ext {
optional = { optionalDeps << it; it }
provided = { providedDeps << it; it }
internal = { internalDeps << it; it }
patchPom = { pom ->
optionalDeps.each { dep ->
pom.dependencies.find { matches(it, dep) }.optional = true
}
providedDeps.each { dep ->
pom.dependencies.find { matches(it, dep) }.scope = "provided"
}
internalDeps.each { dep ->
pom.dependencies.removeAll { matches(it, dep) }
}
// no need to publish test dependencies
pom.dependencies.removeAll { it.scope == "test" }
}
}
afterEvaluate { project ->
def deployers = []
project.install {
deployers << repositories.mavenInstaller
}
deployers*.pom.each {
it.whenConfigured(project.patchPom)
}
}