-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle.kts
245 lines (223 loc) · 6.62 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
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import java.util.*
plugins {
groovy
`kotlin-dsl`
id("com.gradle.plugin-publish")
}
interface Injected {
@get:Inject val fs: FileSystemOperations
}
group = "dev.hargrave"
version = "1.2.0-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
val localrepo: String? = System.getProperty("maven.repo.local")
localrepo?.let {
var rootGradle: Gradle = gradle
while (rootGradle.parent != null) {
rootGradle = rootGradle.parent!!
}
extra.set("maven_repo_local", rootGradle.startParameter.currentDir.resolve(it).normalize().absolutePath)
}
val maven_repo_local: String? by extra
repositories {
mavenCentral()
}
// SourceSet for Kotlin DSL code so that it can be built after the main SourceSet
val dsl: SourceSet by sourceSets.creating
sourceSets {
dsl.apply {
compileClasspath += main.get().output
runtimeClasspath += main.get().output
}
test {
compileClasspath += dsl.output
runtimeClasspath += dsl.output
}
}
configurations {
dsl.compileOnlyConfigurationName {
extendsFrom(compileOnly.get())
}
dsl.implementationConfigurationName {
extendsFrom(implementation.get())
}
dsl.runtimeOnlyConfigurationName {
extendsFrom(runtimeOnly.get())
}
}
// Dependencies
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.3")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.spockframework:spock-core:2.3-groovy-3.0")
testImplementation("biz.aQute.bnd:biz.aQute.bndlib:6.4.1")
}
// Gradle plugin descriptions
gradlePlugin {
website.set("https://github.com/bjhargrave/add-maven-descriptor")
vcsUrl.set("https://github.com/bjhargrave/add-maven-descriptor.git")
plugins {
create("AddMavenDescriptor") {
id = "dev.hargrave.addmavendescriptor"
implementationClass = "dev.hargrave.gradle.addmavendescriptor.AddMavenDescriptorPlugin"
displayName = "Add Maven Descriptor Plugin"
description = "Gradle Plugin to add Maven descriptor information to built jars."
tags.set(listOf("maven", "pom"))
}
}
}
publishing {
publications {
// Main plugin publication
create<MavenPublication>("pluginMaven") {
pom {
name.set(artifactId)
description.set("Add Maven Descriptor")
}
val publication = this
tasks.register<WriteProperties>("generatePomPropertiesFor${publication.name.replaceFirstChar {
it.titlecase(Locale.ROOT)
}}Publication") {
description = "Generates the Maven pom.properties file for publication '${publication.name}'."
group = PublishingPlugin.PUBLISH_TASK_GROUP
destinationFile.value(layout.buildDirectory.file("publications/${publication.name}/pom-default.properties"))
property("groupId", provider { publication.groupId })
property("artifactId", provider { publication.artifactId })
property("version", provider { publication.version })
}
}
// Configure pom metadata
withType<MavenPublication> {
pom {
url.set("https://github.com/bjhargrave/add-maven-descriptor")
organization {
name.set("BJ Hargrave")
url.set("https://github.com/bjhargrave")
}
licenses {
license {
name.set("Apache-2.0")
url.set("https://opensource.org/licenses/Apache-2.0")
distribution.set("repo")
comments.set("This program and the accompanying materials are made available under the terms of the Apache License, Version 2.0.")
}
}
scm {
url.set("https://github.com/bjhargrave/add-maven-descriptor")
connection.set("scm:git:https://github.com/bjhargrave/add-maven-descriptor.git")
developerConnection.set("scm:git:[email protected]:bjhargrave/add-maven-descriptor.git")
tag.set(version)
}
developers {
developer {
id.set("bjhargrave")
name.set("BJ Hargrave")
email.set("[email protected]")
url.set("https://github.com/bjhargrave")
organization.set("IBM")
organizationUrl.set("https://developer.ibm.com")
roles.set(setOf("developer"))
timezone.set("America/New_York")
}
}
}
}
}
}
// Use same jvm target for kotlin code as for java code
tasks.withType<KotlinCompilationTask<KotlinJvmCompilerOptions>>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.fromTarget(java.targetCompatibility.toString()))
}
}
// Disable gradle module metadata
tasks.withType<GenerateModuleMetadata>().configureEach {
enabled = false
}
// Reproducible jars
tasks.withType<AbstractArchiveTask>().configureEach {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// Reproducible javadoc
tasks.withType<Javadoc>().configureEach {
options {
this as StandardJavadocDocletOptions // unsafe cast
isNoTimestamp = true
}
}
tasks.pluginUnderTestMetadata {
// Include dsl SourceSet
pluginClasspath.from(dsl.output)
}
tasks.jar {
// Include dsl SourceSet
from(dsl.output)
// META-INF/maven folder
val metaInfMaven = publishing.publications.named<MavenPublication>("pluginMaven").map {
"META-INF/maven/${it.groupId}/${it.artifactId}"
}
// Include generated pom.xml file
into(metaInfMaven) {
from(tasks.named("generatePomFileForPluginMavenPublication"))
rename { "pom.xml" }
}
// Include generated pom.properties file
into(metaInfMaven) {
from(tasks.named("generatePomPropertiesForPluginMavenPublication"))
rename { "pom.properties" }
}
}
tasks.named<Jar>("sourcesJar") {
// Include dsl SourceSet
from(dsl.allSource)
}
val testresourcesOutput = layout.buildDirectory.dir("testresources")
// Configure test
tasks.test {
useJUnitPlatform()
reports {
junitXml.apply {
isOutputPerTestCase = true
mergeReruns.set(true)
}
}
testLogging {
setExceptionFormat("full")
info {
events("STANDARD_OUT", "STANDARD_ERROR", "STARTED", "FAILED", "PASSED", "SKIPPED")
}
}
val testresourcesSource = layout.projectDirectory.dir("testresources")
inputs.files(testresourcesSource).withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName("testresources")
systemProperty("org.gradle.warning.mode", gradle.startParameter.warningMode.name.lowercase(Locale.ROOT))
maven_repo_local?.let {
systemProperty("maven.repo.local", it)
}
val injected = objects.newInstance<Injected>()
doFirst {
// copy test resources into build dir
injected.fs.delete {
delete(testresourcesOutput)
}
injected.fs.copy {
from(testresourcesSource)
into(testresourcesOutput)
}
}
}
tasks.named<Delete>("cleanTest") {
delete(testresourcesOutput)
}
tasks.withType<ValidatePlugins>().configureEach {
failOnWarning.set(true)
enableStricterValidation.set(true)
}