-
Notifications
You must be signed in to change notification settings - Fork 4
/
build.gradle.kts
188 lines (174 loc) · 6.42 KB
/
build.gradle.kts
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
// Gradle script to build the asm project
plugins {
`java-library` // to build JVM libraries
`maven-publish` // to publish artifacts to Maven repositories
`signing` // to sign artifacts for publication
}
val group = "com.github.stephengold"
val artifact = "asm-all"
val libraryVersion = "3.1.2-SNAPSHOT"
val baseName = "${artifact}-${libraryVersion}" // for artifacts
val websiteUrl = "https://github.com/stephengold/asm"
val javaVendor = System.getProperty("java.vendor")
val javaVersion = JavaVersion.current()
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
tasks.withType<JavaCompile>().all { // Java compile-time options:
options.compilerArgs.add("-Xdiags:verbose")
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_14)) {
// Suppress warnings that source value 7 is obsolete.
options.compilerArgs.add("-Xlint:-options")
}
//options.compilerArgs.add("-Xlint:unchecked")
options.setDeprecation(true) // to provide detailed deprecation warnings
options.encoding = "UTF-8"
if (javaVersion.isCompatibleWith(JavaVersion.VERSION_1_10)) {
options.release = 7
}
}
tasks.withType<Javadoc>().all {
// Disable doclint for JDK8+.
if (javaVersion.isJava8Compatible()) {
(options as CoreJavadocOptions).apply {
addStringOption("Xdoclint:none", "-quiet")
}
}
}
// Register publishing tasks:
tasks.register("install") {
dependsOn("publishMavenPublicationToMavenLocal")
description = "Installs the Maven artifacts to the local repository."
}
tasks.register("release") {
dependsOn("publishMavenPublicationToOSSRHRepository")
description = "Stages the Maven artifacts to Sonatype OSSRH."
}
tasks.jar {
archiveBaseName.set(baseName)
doLast {
println("built using Java $javaVersion ($javaVendor)")
}
manifest {
attributes["Created-By"] = "$javaVersion ($javaVendor)"
}
}
java.withJavadocJar()
tasks.named<Jar>("javadocJar") { archiveBaseName.set(baseName) }
tasks.register<Jar>("sourcesJar") {
archiveBaseName.set(baseName)
archiveClassifier.set("sources")
description = "Creates a JAR of Java sourcecode."
from(sourceSets.main.get().java) // default is ".allSource", which includes resources
}
tasks.named("assemble") { dependsOn("module", "moduleAsc", "pom", "pomAsc") }
tasks.register<Copy>("module") {
dependsOn("generateMetadataFileForMavenPublication")
description = "Copies the module metadata to build/libs."
from("build/publications/maven/module.json")
into("build/libs")
rename("module.json", baseName + ".module")
}
tasks.register<Copy>("moduleAsc") {
dependsOn("signMavenPublication")
description = "Copies the signature of the module metadata to build/libs."
from("build/publications/maven/module.json.asc")
into("build/libs")
rename("module.json.asc", baseName + ".module.asc")
}
tasks.register<Copy>("pom") {
dependsOn("generatePomFileForMavenPublication")
description = "Copies the Maven POM to build/libs."
from("build/publications/maven/pom-default.xml")
into("build/libs")
rename("pom-default.xml", baseName + ".pom")
}
tasks.register<Copy>("pomAsc") {
dependsOn("signMavenPublication")
description = "Copies the signature of the Maven POM to build/libs."
from("build/publications/maven/pom-default.xml.asc")
into("build/libs")
rename("pom-default.xml.asc", baseName + ".pom.asc")
}
publishing {
publications {
create<MavenPublication>("maven") {
artifact(tasks.named("sourcesJar"))
artifactId = artifact
from(components["java"])
groupId = group
pom {
description = project.description
developers {
developer {
name = "Eric Bruneton"
}
developer {
name = "Eugene Kuleshov"
}
developer {
name = "Niko Matsakis"
}
developer {
name = "Chris Nokleberg"
}
developer {
name = "Juozas Baliuka"
}
developer {
name = "Thomas Hallgren"
}
developer {
name = "Bing Ran"
}
}
licenses {
license {
distribution = "repo"
name = "New BSD (3-clause) License"
url = "https://opensource.org/licenses/BSD-3-Clause"
}
}
name = "${group}:${artifact}"
scm {
connection = "scm:git:git://github.com/stephengold/asm.git"
developerConnection = "scm:git:ssh://github.com:stephengold/asm.git"
url = websiteUrl + "/tree/master"
}
url = websiteUrl
}
version = libraryVersion
}
}
// Staging to OSSRH relies on the existence of 2 properties
// (ossrhUsername and ossrhPassword)
// which should be stored in ~/.gradle/gradle.properties
repositories {
maven {
credentials {
username = if (hasProperty("ossrhUsername")) property("ossrhUsername") as String else "Unknown user"
password = if (hasProperty("ossrhPassword")) property("ossrhPassword") as String else "Unknown password"
}
name = "OSSRH"
url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2")
}
}
}
tasks.named("generateMetadataFileForMavenPublication") { dependsOn("pom") }
tasks.named("publishMavenPublicationToMavenLocal") {
dependsOn("assemble")
doLast { println("installed locally as " + baseName) }
}
tasks.named("publishMavenPublicationToOSSRHRepository") { dependsOn("assemble") }
// Register signing tasks:
// Signing relies on the existence of 3 properties
// (signing.keyId, signing.password, and signing.secretKeyRingFile)
// which should be stored in ~/.gradle/gradle.properties
signing {
sign(publishing.publications["maven"])
}
tasks.withType<Sign>().all {
onlyIf { project.hasProperty("signing.keyId") }
}
tasks.named("signMavenPublication") { dependsOn("module") }