-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
build.gradle.kts
222 lines (197 loc) · 5.99 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
plugins {
id("java")
id("eclipse")
id("idea")
id("maven-publish")
id("signing")
id("biz.aQute.bnd.builder") version "7.0.0"
id("net.nemerosa.versioning") version "3.1.0"
id("org.ajoberstar.git-publish") version "4.2.2"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
}
val buildTimeAndDate: OffsetDateTime = OffsetDateTime.now()
val buildDate: String = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate)
val buildTime: String = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate)
val builtByValue = project.findProperty("builtBy") ?: project.property("defaultBuiltBy")
val isSnapshot = project.version.toString().contains("SNAPSHOT")
val docsVersion = if (isSnapshot) "snapshot" else project.version.toString()
val docsDir = layout.buildDirectory.dir("ghpages-docs")
val replaceCurrentDocs = project.hasProperty("replaceCurrentDocs")
description = "@API Guardian"
val moduleName = "org.apiguardian.api"
repositories {
mavenCentral()
}
java {
withJavadocJar()
withSourcesJar()
}
val moduleSourceDir = file("src/module/java")
tasks {
compileJava {
options.release = 6
javaCompiler = project.javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
val compileModule by registering(JavaCompile::class) {
source(moduleSourceDir)
destinationDirectory = layout.buildDirectory.dir("classes/java/modules")
classpath = files(compileJava.map { it.classpath })
inputs.property("moduleName", moduleName)
inputs.property("moduleVersion", project.version)
options.release.set(9)
options.compilerArgs = listOf(
"--module-version", project.version as String,
"--module-source-path", moduleSourceDir.toString(),
"--patch-module", "$moduleName=${sourceSets.main.get().allJava.srcDirs.joinToString(":")}",
"--module", moduleName
)
}
jar {
fun normalizeVersion(versionLiteral: String): String {
val regex = Regex("(\\d+\\.\\d+\\.\\d+).*")
val match = regex.matchEntire(versionLiteral)
require(match != null) {
"Version '$versionLiteral' does not match version pattern, e.g. 1.0.0-QUALIFIER"
}
return match.groupValues[1]
}
manifest {
attributes(
"Created-By" to "${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})",
"Built-By" to builtByValue,
"Build-Date" to buildDate,
"Build-Time" to buildTime,
"Build-Revision" to versioning.info.commit,
"Specification-Title" to project.name,
"Specification-Version" to normalizeVersion(project.version.toString()),
"Specification-Vendor" to "apiguardian.org",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "apiguardian.org",
"Bundle-Name" to project.name,
"Bundle-Description" to project.description,
"Bundle-DocURL" to "https://github.com/apiguardian-team/apiguardian",
"Bundle-Vendor" to "apiguardian.org",
"-exportcontents" to "org.apiguardian.api",
"Bundle-SymbolicName" to moduleName
)
}
from(files(compileModule.flatMap { destinationDirectory.map { it.dir(moduleName) } })) {
include("module-info.class")
}
}
javadoc {
(options as StandardJavadocDocletOptions).apply {
memberLevel = JavadocMemberLevel.PROTECTED
isAuthor = true
header = "@API Guardian"
addStringOption("Xdoclint:html,syntax,reference", "-quiet")
links("https://docs.oracle.com/en/java/javase/11/docs/api/")
}
}
named<Jar>("sourcesJar") {
from("${moduleSourceDir}/${moduleName}") {
include("module-info.java")
}
}
named<Jar>("javadocJar") {
from(javadoc.map { File(it.destinationDir, "element-list") }) {
// For compatibility with older tools, e.g. NetBeans 11
rename { "package-list" }
}
}
withType<Jar>().configureEach {
from(rootDir) {
include("LICENSE")
include("COPYRIGHT")
into("META-INF")
}
}
val prepareDocsForUploadToGhPages by registering(Copy::class) {
dependsOn(javadoc)
outputs.dir(docsDir)
from(layout.buildDirectory.dir("docs")) {
include("javadoc/**")
}
from(layout.buildDirectory.dir("docs/javadoc")) {
// For compatibility with pre JDK 10 versions of the Javadoc tool
include("element-list")
rename { "api/package-list" }
}
into(docsDir.map { it.dir(docsVersion) })
filesMatching("javadoc/**") {
path = path.replace("javadoc/", "api/")
}
includeEmptyDirs = false
}
val createCurrentDocsFolder by registering(Copy::class) {
dependsOn(prepareDocsForUploadToGhPages)
enabled = replaceCurrentDocs
outputs.dir("${docsDir}/current")
from(docsDir.map { it.dir(docsVersion) })
into(docsDir.map { it.dir("current") })
}
gitPublishCopy {
dependsOn(prepareDocsForUploadToGhPages, createCurrentDocsFolder)
}
}
if (!isSnapshot) {
signing {
sign(publishing.publications)
}
}
nexusPublishing {
packageGroup.set(group.toString())
repositories {
sonatype()
}
}
publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
pom {
name.set("${project.group}:${project.name}")
description.set("@API Guardian")
url.set("https://github.com/apiguardian-team/apiguardian")
scm {
connection.set("scm:git:git://github.com/apiguardian-team/apiguardian.git")
developerConnection.set("scm:git:git://github.com/apiguardian-team/apiguardian.git")
url.set("https://github.com/apiguardian-team/apiguardian")
}
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("apiguardian")
name.set("@API Guardian Team")
email.set("[email protected]")
}
}
}
}
}
}
gitPublish {
repoUri.set("https://github.com/apiguardian-team/apiguardian.git")
branch.set("gh-pages")
contents {
from(docsDir)
into("docs")
}
preserve {
include("**/*")
exclude("docs/$docsVersion/**")
if (replaceCurrentDocs) {
exclude("docs/current/**")
}
}
}