-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathlib.gradle
More file actions
157 lines (130 loc) · 4.6 KB
/
lib.gradle
File metadata and controls
157 lines (130 loc) · 4.6 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import org.apache.tools.ant.taskdefs.condition.Os
String findCommand(String dir, String command) {
def extension = Os.isFamily(Os.FAMILY_WINDOWS) ? ".exe" : ""
def cmd = "$dir/$command$extension"
if (! new File(cmd).exists()) {
throw new Exception("Command $command not found in dir $dir")
}
cmd
}
String findJavaCommand(String command) {
def jh = System.getenv("JAVA8_HOME")
if (jh == null) {
throw new Exception("Environment variable JAVA8_HOME not set")
}
findCommand("$jh/bin", command)
}
Boolean doSigning(String signingAllowed, Boolean doModule) {
def b = signingAllowed.trim() == "true" && doModule
// println("signModule: ${project.name} signingAllowed: $signingAllowed doModule: $doModule")
b
}
void performSigning(String signingAllowed, Boolean doModule) {
signing {
required { doSigning(signingAllowed, doModule) }
sign configurations.archives
}
}
def customisePom(pom, gradleProject) {
pom.withXml {
def root = asNode()
// add all items necessary for maven central publication
root.children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name project.pomProjectName
description project.projectDescription
url project.projectUrl
organization {
name project.pomOrganisation
url project.projectUrl
}
issueManagement {
system 'GitHub'
url project.issueUrl
}
licenses {
license {
name project.licenseName
url project.licenseUrl
distribution 'repo'
}
}
scm {
url project.githubUrl
connection project.scmGitFile
developerConnection project.scmSshGitFile
}
}
}
}
void configureUpload(String signingEnabled, Boolean signModule, Boolean uploadModule) {
if (uploadModule) {
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.name
version project.version
from components.java
customisePom(pom, rootProject)
artifact sourcesJar
artifact javadocJar
if (doSigning(signingEnabled, signModule)) {
// sign the pom
pom.withXml {
def pomFile = file("${project.buildDir}/generated-pom.xml.asc")
writeTo(pomFile)
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
extension = 'pom.asc'
}
pomFile.delete()
}
// sign the artifacts
project.tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc|jre8|jre9)\.jar\.asc$/
if (matcher.find()) {
classifier = matcher.group(1)
} else {
classifier = null
}
extension = 'jar.asc'
}
}
}
}
}
repositories {
maven {
url project.sonatypeUploadUrl
credentials {
username sonatypeUsername
password sonatypePassword
}
}
}
}
model {
tasks.publishMavenJavaPublicationToMavenLocal {
dependsOn(project.tasks.signArchives)
}
tasks.publishMavenJavaPublicationToMavenRepository {
dependsOn(project.tasks.signArchives)
}
tasks.publish {
dependsOn(project.tasks.build)
}
// tasks.install {
// dependsOn(project.tasks.build)
// }
}
}
}
ext {
findJavaCommand = this.&findJavaCommand
doSigning = this.&doSigning
performSigning = this.&performSigning
configureUpload = this.&configureUpload
}