-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
192 lines (171 loc) · 5.64 KB
/
build.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
jcenter()
maven { url "http://repo.spring.io/snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "http://10.32.11.210:8081/nexus/content/groups/public" }
}
group = 'org.nofdev'
sourceCompatibility = 1.8
targetCompatibility = 1.8
[compileJava, compileTestJava, compileGroovy, compileTestGroovy]*.options*.encoding = 'UTF-8'
dependencies {
compile "org.codehaus.groovy:groovy-all:2.4.4"
}
task wrapper(type: Wrapper) {
gradleVersion = '2.5'
}
apply plugin: 'maven-publish'
apply plugin: 'signing'
def isMvnCentral
def isMvnSign
if (hasProperty("isMavenCentral")) {
isMvnCentral = isMavenCentral
}
if (hasProperty("isMavenSign")) {
isMvnSign = isMavenSign
}
task sourceJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
ext {
pomFilePath = "${project.projectDir}/tmp/pom.xml"
pomFile = file(pomFilePath)
}
configurations {
pom
}
// summarize artifacts
artifacts {
archives jar
archives sourceJar
archives javadocJar
if (pomFile.exists()) {
pom pomFile
}
}
// sign all artifacts
task signJars(type: Sign, dependsOn: [jar, javadocJar, sourceJar]) {
sign configurations.archives
}
// sign pom
task signPom(type: Sign) {
sign configurations.pom
}
// defining which tasks should be called
if (project.ext.pomFile.exists() && isMvnCentral == "true" && isMavenSign == "true") {
task preparePublication(dependsOn: [signJars, signPom])
} else {
// task preparePublication(dependsOn: signJars)
}
// extract signature file and give them proper name
def getSignatureFiles = {
def allFiles = project.tasks.signJars.signatureFiles.collect { it }
def signedSources = allFiles.find { it.name.contains('-sources') }
def signedJavadoc = allFiles.find { it.name.contains('-javadoc') }
def signedJar = (allFiles - [signedSources, signedJavadoc])[0]
return [
[archive: signedSources, classifier: 'sources', extension: 'jar.asc'],
[archive: signedJavadoc, classifier: 'javadoc', extension: 'jar.asc'],
[archive: signedJar, classifier: null, extension: 'jar.asc']
]
}
// extract pom signature
def getPomSignature = {
return project.tasks.signPom.signatureFiles.collect { it }[0]
}
// ./graldew clean generatePomFileForJarPublication -PisMavenCentral=true
// ./gradlew clean pP publish -PmavenUrl=xxx -PmavenUser=xxx -PmavenPassword=xxx -Psigning.keyId=xxx -Psigning.password=xxx -Psigning.secretKeyRingFile=xxx -PisMavenCentral=true
publishing {
publications {
jar(MavenPublication) {
from components.java
pom.withXml {
// add required elements
asNode().children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
name 'service-core'
description 'The basic componet of Nofdev RPC framework'
url 'https://github.com/nofdev/service-core'
scm {
url 'https://github.com/nofdev/service-core.git'
connection 'scm:git:git://github.com/nofdev/service-core.git'
developerConnection 'scm:git:ssh:[email protected]:nofdev/service-core.git'
}
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/license/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'mengqiang'
name 'Quincy Meng'
email '[email protected]'
}
}
}
}
artifact sourceJar
artifact javadocJar
if (project.ext.pomFile.exists() && isMvnCentral == "true" && isMavenSign == "true") {
getSignatureFiles().each { signature ->
artifact(signature.archive) {
classifier = signature.classifier
extension = signature.extension
}
}
artifact(getPomSignature()) {
classifier = null
extension = 'pom.asc'
}
}
}
// gpgJars(MavenPublication) {
// getSignatureFiles().each { signature ->
// artifact(signature.archive) {
// classifier = signature.classifier
// extension = signature.extension
// }
// }
// }
//
// if (project.ext.pomFile.exists()) {
// gpgPom(MavenPublication) {
// artifact(getPomSignature()) {
// classifier = null
// extension = 'pom.asc'
// }
// }
// }
}
repositories {
if (project.ext.pomFile.exists() && isMvnCentral == "true") {
maven {
url mavenUrl
credentials {
username mavenUser
password mavenPassword
}
}
} else {
mavenLocal()
}
}
}
model {
if (isMvnCentral == "true") {
tasks.generatePomFileForJarPublication {
destination = project.ext.pomFile
}
}
}