This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
maven.gradle
85 lines (75 loc) · 2.52 KB
/
maven.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
apply plugin: 'maven'
if (project.hasProperty('artifactoryUrl')
&& project.hasProperty('artifactoryUsername')
&& project.hasProperty('artifactoryPassword')) {
repoUpload(taskName: 'uploadArtifactory',
url: artifactoryUrl,
username: artifactoryUsername,
password: artifactoryPassword)
}
if (project.hasProperty('publicRepository')) {
repoUpload(taskName: 'uploadGithub',
url: "file://localhost/$publicRepository")
}
def repoUpload(Map<String, String> options) {
def taskName = options.taskName
def repoUrl = options.url
def username = null
def passwd = null
def auth = options.containsKey("username") && options.containsKey("password")
if (auth) {
username = options.username
passwd = options.password
}
task(taskName, type: Upload) {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: repoUrl) {
if (auth) {
authentication(userName: username, password: passwd)
}
}
pom.project {
name = archivesBaseName
packaging = 'jar'
description projectDescription
url projectUrl
}
//mess with the generated pom to remove test dependencies from published artifacts
pom.withXml { XmlProvider xmlProvider ->
def xml = xmlProvider.asString()
def pomXml = new XmlParser().parse(new ByteArrayInputStream(xml.toString().bytes))
pomXml.dependencies.dependency.each { dep ->
if (dep.scope.text() != 'compile') {
def parent = dep.parent()
parent.remove(dep)
}
}
// add exclusion nodes (only for compile conf) since the maven plugin
// doesn't handle them as of gradle 1.9
project.configurations.compile.allDependencies.findAll {
it instanceof ModuleDependency && !it.excludeRules.isEmpty()
}.each { ModuleDependency dep ->
def xmlDep = pomXml.dependencies.dependency.find {
it.groupId[0].text() == dep.group && it.artifactId[0].text() == dep.name
}
def xmlExclusions = xmlDep.exclusions
if (!xmlExclusions) xmlExclusions = xmlDep.appendNode('exclusions')
dep.excludeRules.each { ExcludeRule rule ->
def xmlExclusion = xmlExclusions.appendNode('exclusion')
xmlExclusion.appendNode('groupId', rule.group)
xmlExclusion.appendNode('artifactId', rule.module ?: '*')
}
}
def newXml = new StringWriter()
def printer = new XmlNodePrinter(new PrintWriter(newXml))
printer.preserveWhitespace = true
printer.print(pomXml)
xml.setLength(0)
xml.append(newXml.toString())
}
}
}
}
}