-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
194 lines (153 loc) · 5.17 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
// http://stackoverflow.com/questions/3445825/gradle-how-do-i-build-a-jar-with-a-lib-dir-with-other-jars-in-it
// http://medium.com/@nmauti/sign-and-publish-on-maven-central-a-project-with-the-new-maven-publish-gradle-plugin-22a72a4bfd4b
// http://www.albertgao.xyz/2018/01/18/how-to-publish-artifact-to-maven-central-via-gradle
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'
sourceCompatibility = 1.9
targetCompatibility = 1.9
sourceSets {
main {
java {
srcDir 'src'
}
}
}
tasks.withType(JavaCompile) {
options.fork = true
options.debug = true
}
repositories {
mavenCentral()
}
def jarName = "topseed4j.jar"
def vversion = 'v1.04.01'
task cleanUp() {
println 'clean build'
delete './build'
}
task buildJar(type: GradleBuild) {
tasks = ['cleanUp', 'compileJava', 'jar']
}
defaultTasks 'buildJar'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
jar { // modify release
manifest {
attributes(
'Implementation-Version': vversion
)}
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
///// release to maven: //////////////////////////////////////////////
//check gradle properties keyID (last 8) and secretKeyRingFile. In Windows (gpg4win), use Cleopatra rightclick on item to 'Export Secret Keys' to topseed4j root folder
//gradle publish
//Open Nexus Repository Manager at https://oss.sonatype.org/#welcome
//Click the Log in at upper right corner
//At the right side, click Staging Repositories
////Search your com.github.appthings
//Select the right item and click the Close button to close it. It’s like to finalize the uploading thing.
//Click the Refresh button to get the latest updates. Remember this trick, we are in 1980s, no ajax yet.
//Click Release Button.
signing {
sign configurations.archives
}
publishing {
publications {
mavenJava(MavenPublication) {
customizePom(pom)
groupId 'com.github.appthings'
artifactId 'topseed4j'
version vversion
from components.java
// create the sign pom artifact
pom.withXml {
def pomFile = file("${project.buildDir}/generated-pom.xml")
writeTo(pomFile)
def pomAscFile = signing.sign(pomFile).signatureFiles[0]
artifact(pomAscFile) {
classifier = null
extension = 'pom.asc'
}
}
// create the signed artifacts
project.tasks.signArchives.signatureFiles.each {
artifact(it) {
def matcher = it.file =~ /-(sources|javadoc)\.jar\.asc$/
if (matcher.find()) {
classifier = matcher.group(1)
} else {
classifier = null
}
extension = 'jar.asc'
}
}
}
}
repositories {
maven {
url "https://oss.sonatype.org/service/local/staging/deploy/maven2"
credentials {
username sonatypeUsername
password sonatypePassword
}
}
}
}
def customizePom(pom) {
pom.withXml {
def root = asNode()
// eliminate test-scoped dependencies (no need in maven central POMs)
root.dependencies.removeAll { dep ->
dep.scope == "test"
}
// add all items necessary for maven central publication
root.children().last() + {
resolveStrategy = Closure.DELEGATE_FIRST
description 'topseed4j'
name 'topseed4j'
url 'https://github.com/appthings/topseed4j'
organization {
name 'com.github.appthings'
url 'https://github.com/appthings/topseed4j'
}
issueManagement {
system 'GitHub'
url 'https://github.com/appthings/topseed4j/issues'
}
licenses {
license {
name 'Attribution 4.0 International (CC BY 4.0)'
url 'https://creativecommons.org/licenses/by/4.0'
distribution 'repo'
}
}
scm {
url 'https://github.com/appthings/topseed4j'
connection 'scm:git:git://github.com/appthings/topseed4j.git'
developerConnection 'scm:git:ssh://[email protected]:appthings/topseed4j.git'
}
developers {
developer {
name 'several'
}
}
}
}
}
model {
tasks.signArchives {
dependsOn project.tasks.buildJar
}
tasks.generatePomFileForMavenJavaPublication {
dependsOn project.tasks.signArchives
destination = file("${project.buildDir}/generated-pom.xml")
}
tasks.publishMavenJavaPublicationToMavenLocal {
dependsOn project.tasks.generatePomFileForMavenJavaPublication
}
tasks.publishMavenJavaPublicationToMavenRepository {
dependsOn project.tasks.generatePomFileForMavenJavaPublication
}
}