| 1 |
import java.time.OffsetDateTime |
| 2 |
import java.time.format.DateTimeFormatter |
| 3 |
|
| 4 |
plugins { |
| 5 |
id("java") |
| 6 |
id("eclipse") |
| 7 |
id("idea") |
| 8 |
id("maven-publish") |
| 9 |
id("signing") |
| 10 |
id("biz.aQute.bnd.builder") version "5.3.0" |
| 11 |
id("net.nemerosa.versioning") version "2.14.0" |
| 12 |
id("org.ajoberstar.git-publish") version "3.0.0" |
| 13 |
id("io.github.gradle-nexus.publish-plugin") version "1.1.0" |
| 14 |
} |
| 15 |
|
| 16 |
val buildTimeAndDate = OffsetDateTime.now() |
| 17 |
val buildDate = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate) |
| 18 |
val buildTime = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate) |
| 19 |
val builtByValue = project.findProperty("builtBy") ?: project.property("defaultBuiltBy") |
| 20 |
|
| 21 |
val isSnapshot = project.version.toString().contains("SNAPSHOT") |
| 22 |
val docsVersion = if (isSnapshot) "snapshot" else project.version |
| 23 |
val docsDir = File(buildDir, "ghpages-docs") |
| 24 |
val replaceCurrentDocs = project.hasProperty("replaceCurrentDocs") |
| 25 |
|
| 26 |
description = "@API Guardian" |
| 27 |
val moduleName = "org.apiguardian.api" |
| 28 |
|
| 29 |
repositories { |
| 30 |
mavenCentral() |
| 31 |
} |
| 32 |
|
| 33 |
java { |
| 34 |
withJavadocJar() |
| 35 |
withSourcesJar() |
| 36 |
} |
| 37 |
|
| 38 |
val moduleSourceDir = file("src/module/java") |
| 39 |
|
| 40 |
tasks { |
| 41 |
compileJava { |
| 42 |
options.release.set(6) |
| 43 |
} |
| 44 |
|
| 45 |
val compileModule by registering(JavaCompile::class) { |
| 46 |
source(moduleSourceDir) |
| 47 |
destinationDir = file("$buildDir/classes/java/modules") |
| 48 |
classpath = files(compileJava.map { it.classpath }) |
| 49 |
inputs.property("moduleName", moduleName) |
| 50 |
inputs.property("moduleVersion", project.version) |
| 51 |
options.release.set(9) |
| 52 |
options.compilerArgs = listOf( |
| 53 |
"--module-version", project.version as String, |
| 54 |
"--module-source-path", moduleSourceDir.toString(), |
| 55 |
"--patch-module", "$moduleName=${sourceSets.main.get().allJava.srcDirs.joinToString(":")}", |
| 56 |
"--module", moduleName |
| 57 |
) |
| 58 |
} |
| 59 |
|
| 60 |
jar { |
| 61 |
fun normalizeVersion(versionLiteral: String): String { |
| 62 |
val regex = Regex("(\\d+\\.\\d+\\.\\d+).*") |
| 63 |
val match = regex.matchEntire(versionLiteral) |
| 64 |
require(match != null) { |
| 65 |
"Version '$versionLiteral' does not match version pattern, e.g. 1.0.0-QUALIFIER" |
| 66 |
} |
| 67 |
return match.groupValues[1] |
| 68 |
} |
| 69 |
manifest { |
| 70 |
attributes( |
| 71 |
"Created-By" to "${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${System.getProperty("java.vm.version")})", |
| 72 |
"Built-By" to builtByValue, |
| 73 |
"Build-Date" to buildDate, |
| 74 |
"Build-Time" to buildTime, |
| 75 |
"Build-Revision" to versioning.info.commit, |
| 76 |
"Specification-Title" to project.name, |
| 77 |
"Specification-Version" to normalizeVersion(project.version.toString()), |
| 78 |
"Specification-Vendor" to "apiguardian.org", |
| 79 |
"Implementation-Title" to project.name, |
| 80 |
"Implementation-Version" to project.version, |
| 81 |
"Implementation-Vendor" to "apiguardian.org", |
| 82 |
"Bundle-Name" to project.name, |
| 83 |
"Bundle-Description" to project.description, |
| 84 |
"Bundle-DocURL" to "https://github.com/apiguardian-team/apiguardian", |
| 85 |
"Bundle-Vendor" to "apiguardian.org", |
| 86 |
"-exportcontents" to "org.apiguardian.api", |
| 87 |
"Bundle-SymbolicName" to moduleName |
| 88 |
) |
| 89 |
} |
| 90 |
from(files(compileModule.map { "${it.destinationDir}/${moduleName}" })) { |
| 91 |
include("module-info.class") |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
javadoc { |
| 96 |
(options as StandardJavadocDocletOptions).apply { |
| 97 |
memberLevel = JavadocMemberLevel.PROTECTED |
| 98 |
isAuthor = true |
| 99 |
header = "@API Guardian" |
| 100 |
addStringOption("Xdoclint:html,syntax,reference", "-quiet") |
| 101 |
links("https://docs.oracle.com/en/java/javase/11/docs/api/") |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
named<Jar>("sourcesJar") { |
| 106 |
from("${moduleSourceDir}/${moduleName}") { |
| 107 |
include("module-info.java") |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
named<Jar>("javadocJar") { |
| 112 |
from(javadoc.map { File(it.destinationDir, "element-list") }) { |
| 113 |
// For compatibility with older tools, e.g. NetBeans 11 |
| 114 |
rename { "package-list" } |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
withType<Jar>().configureEach { |
| 119 |
from(rootDir) { |
| 120 |
include("LICENSE") |
| 121 |
into("META-INF") |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
val prepareDocsForUploadToGhPages by registering(Copy::class) { |
| 126 |
dependsOn(javadoc) |
| 127 |
outputs.dir(docsDir) |
| 128 |
|
| 129 |
from("$buildDir/docs") { |
| 130 |
include("javadoc/**") |
| 131 |
} |
| 132 |
from("$buildDir/docs/javadoc") { |
| 133 |
// For compatibility with pre JDK 10 versions of the Javadoc tool |
| 134 |
include("element-list") |
| 135 |
rename { "api/package-list" } |
| 136 |
} |
| 137 |
into("${docsDir}/${docsVersion}") |
| 138 |
filesMatching("javadoc/**") { |
| 139 |
path = path.replace("javadoc/", "api/") |
| 140 |
} |
| 141 |
includeEmptyDirs = false |
| 142 |
} |
| 143 |
|
| 144 |
val createCurrentDocsFolder by registering(Copy::class) { |
| 145 |
dependsOn(prepareDocsForUploadToGhPages) |
| 146 |
enabled = replaceCurrentDocs |
| 147 |
outputs.dir("${docsDir}/current") |
| 148 |
|
| 149 |
from("${docsDir}/${docsVersion}") |
| 150 |
into("${docsDir}/current") |
| 151 |
} |
| 152 |
|
| 153 |
gitPublishCommit { |
| 154 |
dependsOn(prepareDocsForUploadToGhPages, createCurrentDocsFolder) |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
if (!isSnapshot) { |
| 159 |
signing { |
| 160 |
sign(publishing.publications) |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
nexusPublishing { |
| 165 |
packageGroup.set(group.toString()) |
| 166 |
repositories { |
| 167 |
sonatype() |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
publishing { |
| 172 |
publications { |
| 173 |
create<MavenPublication>("maven") { |
| 174 |
from(components["java"]) |
| 175 |
pom { |
| 176 |
name.set("${project.group}:${project.name}") |
| 177 |
description.set("@API Guardian") |
| 178 |
url.set("https://github.com/apiguardian-team/apiguardian") |
| 179 |
scm { |
| 180 |
connection.set("scm:git:git://github.com/apiguardian-team/apiguardian.git") |
| 181 |
developerConnection.set("scm:git:git://github.com/apiguardian-team/apiguardian.git") |
| 182 |
url.set("https://github.com/apiguardian-team/apiguardian") |
| 183 |
} |
| 184 |
licenses { |
| 185 |
license { |
| 186 |
name.set("The Apache License, Version 2.0") |
| 187 |
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
| 188 |
} |
| 189 |
} |
| 190 |
developers { |
| 191 |
developer { |
| 192 |
id.set("apiguardian") |
| 193 |
name.set("@API Guardian Team") |
| 194 |
email.set("[email protected]") |
| 195 |
} |
| 196 |
} |
| 197 |
} |
| 198 |
} |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
gitPublish { |
| 203 |
repoUri.set("https://github.com/apiguardian-team/apiguardian.git") |
| 204 |
branch.set("gh-pages") |
| 205 |
|
| 206 |
contents { |
| 207 |
from(docsDir) |
| 208 |
into("docs") |
| 209 |
} |
| 210 |
|
| 211 |
preserve { |
| 212 |
include("**/*") |
| 213 |
exclude("docs/$docsVersion/**") |
| 214 |
if (replaceCurrentDocs) { |
| 215 |
exclude("docs/current/**") |
| 216 |
} |
| 217 |
} |
| 218 |
} |