This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
forked from nnym/unsafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
193 lines (162 loc) · 5.89 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
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
plugins {
with(Plugins) {
// Language Plugins
`java-library`
// Git Repo Information
id("org.ajoberstar.grgit") version GRGIT
// Maven Publication
id("io.github.gradle-nexus.publish-plugin") version NEXUS_PUBLISH
`maven-publish`
signing
}
}
group = Coordinates.GROUP
version = Coordinates.VERSION
// What JVM version should this project compile to
val targetVersion = "1.8"
// What JVM version this project is written in
val sourceVersion = "1.8"
// Maven Repositories
repositories {
mavenLocal()
mavenCentral()
maven("https://jitpack.io")
}
// Project Dependencies
dependencies {
with(Dependencies) {
annotationProcessor("com.github.stardust-enterprises", "uncheck", UNCHECK)
testImplementation("org.junit.jupiter", "junit-jupiter", JUNIT)
}
}
tasks {
test {
useJUnitPlatform()
}
// Configure JVM versions
compileJava {
targetCompatibility = targetVersion
sourceCompatibility = sourceVersion
}
// The original artifact, we just have to add the API source output and the
// LICENSE file.
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]
}
val buildTimeAndDate = OffsetDateTime.now()
val buildDate = DateTimeFormatter.ISO_LOCAL_DATE.format(buildTimeAndDate)
val buildTime = DateTimeFormatter.ofPattern("HH:mm:ss.SSSZ").format(buildTimeAndDate)
mapOf("Created-By" to "${System.getProperty("java.version")} (${System.getProperty("java.vendor")} ${
System.getProperty("java.vm.version")
})",
"Build-Date" to buildDate,
"Build-Time" to buildTime,
"Build-Revision" to grgit.log()[0].id,
"Specification-Title" to project.name,
"Specification-Version" to normalizeVersion(project.version.toString()),
"Specification-Vendor" to Coordinates.VENDOR,
"Implementation-Title" to Coordinates.NAME,
"Implementation-Version" to Coordinates.VERSION,
"Implementation-Vendor" to Coordinates.VENDOR,
"Bundle-Name" to Coordinates.NAME,
"Bundle-Description" to Coordinates.DESC,
"Bundle-DocURL" to "https://${Coordinates.GIT_HOST}/${Coordinates.REPO_ID}",
"Bundle-Vendor" to Coordinates.VENDOR,
"Bundle-SymbolicName" to Coordinates.GROUP + '.' + Coordinates.NAME).forEach { (k, v) ->
manifest.attributes[k] = v
}
from("LICENSE")
}
// Source artifact, including everything the 'main' does but not compiled.
create("sourcesJar", Jar::class) {
group = "build"
archiveClassifier.set("sources")
from(sourceSets["main"].allSource)
from("LICENSE")
}
// The Javadoc artifact, containing the Dokka output and the LICENSE file.
create("javadocJar", Jar::class) {
group = "build"
archiveClassifier.set("javadoc")
dependsOn(javadoc)
from(javadoc)
from("LICENSE")
}
}
// Define the default artifacts' tasks
val defaultArtifactTasks = arrayOf(
tasks["sourcesJar"],
tasks["javadocJar"],
)
// Declare the artifacts
artifacts {
defaultArtifactTasks.forEach(::archives)
}
publishing.publications {
// Sets up the Maven integration.
create("mavenJava", MavenPublication::class.java) {
from(components["java"])
defaultArtifactTasks.forEach(::artifact)
with(Coordinates) {
pom {
name.set(NAME)
description.set(DESC)
url.set("https://$GIT_HOST/$REPO_ID")
with(Pom) {
licenses {
licenses.forEach {
license {
name.set(it.name)
url.set(it.url)
distribution.set(it.distribution)
}
}
}
developers {
developers.forEach {
developer {
id.set(it.id)
name.set(it.name)
}
}
}
}
scm {
connection.set("scm:git:git://$GIT_HOST/$REPO_ID.git")
developerConnection.set("scm:git:ssh://$GIT_HOST/$REPO_ID.git")
url.set("https://$GIT_HOST/$REPO_ID")
}
}
}
// Configure the signing extension to sign this Maven artifact.
signing.sign(this)
}
}
// Configure publishing to Maven Central
nexusPublishing.repositories.sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
// Skip this step if environment variables NEXUS_USERNAME or NEXUS_PASSWORD aren't set.
username.set(properties["NEXUS_USERNAME"] as? String ?: return@sonatype)
password.set(properties["NEXUS_PASSWORD"] as? String ?: return@sonatype)
}
// Task priority
tasks.getByName("closeAndReleaseSonatypeStagingRepository")
.mustRunAfter("publishToSonatype")
// Wrapper task since calling both one after the other
// in IntellIJ seems to cause some problems.
tasks.create("releaseToSonatype") {
this.dependsOn(
"publishToSonatype",
"closeAndReleaseSonatypeStagingRepository"
)
this.group = "publishing"
}