-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle.kts
282 lines (233 loc) · 8.44 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import java.net.URL
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
plugins {
with(Plugins) {
// Language Plugins
`java-library`
kotlin("jvm") version KOTLIN
// Git Repo Information
id("org.ajoberstar.grgit") version GRGIT
// Code Quality
id("org.jlleitschuh.gradle.ktlint") version KTLINT
// Documentation Generation
id("org.jetbrains.dokka") version DOKKA
// Gradle Plugin Portal Publication
id("com.gradle.plugin-publish") version GRADLE_PLUGIN_PUBLISH
`java-gradle-plugin`
`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()
Repositories.mavenUrls.forEach(::maven)
}
// Project Dependencies
dependencies {
compileOnly(gradleApi())
with(Dependencies) {
kotlinModules.forEach {
implementation("org.jetbrains.kotlin", "kotlin-$it", KOTLIN)
}
implementation("fr.stardustenterprises", "stargrad", STARGRAD)
implementation("fr.stardustenterprises", "plat4k", PLAT4K)
implementation("org.tomlj", "tomlj", TOMLJ)
implementation("commons-io", "commons-io", COMMONS_IO)
implementation("com.google.code.gson", "gson", GSON)
implementation("net.lingala.zip4j", "zip4j", ZIP4J)
testImplementation("org.jetbrains.kotlin", "kotlin-test", KOTLIN)
}
}
configurations {
// Makes all the configurations use the same Kotlin version.
all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(Dependencies.KOTLIN)
}
}
}
}
// The latest commit ID
val buildRevision: String = grgit.log()[0].id ?: "dev"
// Disable unneeded rules
ktlint {
this.disabledRules.add("no-wildcard-imports")
}
tasks {
test {
useJUnitPlatform()
}
// Configure JVM versions
compileKotlin {
kotlinOptions.jvmTarget = targetVersion
}
compileJava {
targetCompatibility = targetVersion
sourceCompatibility = sourceVersion
}
dokkaHtml {
val moduleFile = File(projectDir, "MODULE.temp.md")
run {
// In order to have a description on the rendered docs, we have to have
// a file with the # Module thingy in it. That's what we're
// automagically creating here.
doFirst {
moduleFile.writeText("# Module ${Coordinates.NAME}\n${Coordinates.DESC}")
}
doLast {
moduleFile.delete()
}
}
moduleName.set(Coordinates.NAME)
dokkaSourceSets.configureEach {
displayName.set("${Coordinates.NAME} on ${Coordinates.GIT_HOST}")
includes.from(moduleFile.path)
skipDeprecated.set(false)
includeNonPublic.set(false)
skipEmptyPackages.set(true)
reportUndocumented.set(true)
suppressObviousFunctions.set(true)
// Link the source to the documentation
sourceLink {
localDirectory.set(file("src"))
remoteUrl.set(URL("https://${Coordinates.GIT_HOST}/${Coordinates.REPO_ID}/tree/trunk/src"))
}
// External documentation link template
// externalDocumentationLink {
// url.set(URL("https://javadoc.io/doc/net.java.dev.jna/jna/5.10.0/"))
// }
}
}
// 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)
val javaVersion = System.getProperty("java.version")
val javaVendor = System.getProperty("java.vendor")
val javaVmVersion = System.getProperty("java.vm.version")
mapOf(
"Created-By" to "$javaVersion ($javaVendor $javaVmVersion)",
"Build-Date" to buildDate,
"Build-Time" to buildTime,
"Build-Revision" to buildRevision,
"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"
val dokkaHtml = getByName("dokkaHtml")
archiveClassifier.set("javadoc")
dependsOn(dokkaHtml)
from(dokkaHtml)
from("LICENSE")
}
}
// Define the default artifacts' tasks
val defaultArtifactTasks = arrayOf(
tasks["sourcesJar"],
tasks["javadocJar"]
)
// Declare the artifacts
artifacts {
defaultArtifactTasks.forEach(::archives)
}
gradlePlugin {
plugins {
create("wrapperPlugin") {
displayName = "Rust Wrapper"
description = "A plugin that wraps Rust's build systems, for embedding Rust libraries in Java projects."
id = "fr.stardustenterprises.rust.wrapper"
implementationClass = "fr.stardustenterprises.gradle.rust.wrapper.WrapperPlugin"
}
create("importerPlugin") {
displayName = "Rust Importer"
description = "A plugin that makes it possible to import outputs from Rust from another Gradle project."
id = "fr.stardustenterprises.rust.importer"
implementationClass = "fr.stardustenterprises.gradle.rust.importer.ImporterPlugin"
}
}
}
pluginBundle {
vcsUrl = "https://github.com/${Coordinates.REPO_ID}"
website = "https://github.com/${Coordinates.REPO_ID}"
tags = listOf("rust", "rustlang", "cargo", "native", "wrapper")
}
publishing.publications {
create<MavenPublication>("mavenJava") {
groupId = Coordinates.GROUP
version = Coordinates.VERSION
pom {
val repo = Coordinates.REPO_ID
name.set(Coordinates.NAME)
description.set(Coordinates.DESC)
url.set("https://github.com/$repo")
licenses {
Pom.licenses.forEach {
license {
name.set(it.name)
url.set(it.url)
}
}
}
developers {
Pom.developers.forEach {
developer {
id.set(it.id)
name.set(it.name)
}
}
}
scm {
connection.set("scm:git:git://github.com/$repo.git")
developerConnection.set("scm:git:ssh://github.com/$repo.git")
url.set("https://github.com/$repo")
}
}
// Configure the signing extension to sign this Maven artifact.
signing {
isRequired = project.properties["signing.keyId"] != null
sign(this@create)
}
}
}