/
build.gradle.kts
280 lines (260 loc) · 8.48 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
plugins {
`java-gradle-plugin`
groovy
`kotlin-dsl`
id("maven-publish")
id("com.gradle.plugin-publish") version "1.0.0"
}
interface Injected {
@get:Inject val fs: FileSystemOperations
}
// From gradle.properties
val bnd_group: String by project
val bnd_version: String by project
val bnd_distrepo: String by project
group = bnd_group
version = bnd_version
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}
val maven_repo_local: String? by rootProject.extra
repositories {
mavenLocal {
maven_repo_local?.let {
url = uri(it)
}
metadataSources {
mavenPom()
artifact()
}
}
mavenCentral()
}
// SourceSet for Kotlin DSL code so that it can be built after the main SourceSet
sourceSets {
val dsl by registering {
compileClasspath += main.get().output
runtimeClasspath += main.get().output
}
test {
compileClasspath += dsl.get().output
runtimeClasspath += dsl.get().output
}
}
configurations {
val dslCompileOnly by existing {
extendsFrom(compileOnly.get())
}
val dslImplementation by existing {
extendsFrom(implementation.get())
}
val dslRuntimeOnly by existing {
extendsFrom(runtimeOnly.get())
}
}
// Dependencies
dependencies {
compileOnly(localGroovy())
compileOnly(gradleApi())
implementation("biz.aQute.bnd:biz.aQute.bnd.util:${version}")
implementation("biz.aQute.bnd:biz.aQute.bndlib:${version}")
implementation("biz.aQute.bnd:biz.aQute.repository:${version}")
implementation("biz.aQute.bnd:biz.aQute.resolve:${version}")
runtimeOnly("biz.aQute.bnd:biz.aQute.bnd.embedded-repo:${version}")
testImplementation(gradleTestKit())
testImplementation("org.spockframework:spock-core:2.1-groovy-3.0")
}
// Gradle plugin descriptions
gradlePlugin {
plugins {
create("Bnd") {
id = "biz.aQute.bnd"
implementationClass = "aQute.bnd.gradle.BndPlugin"
displayName = "Bnd Gradle Plugin for Bnd Workspace Projects"
description = "Gradle Plugin for developing OSGi bundles with Bnd using the Bnd Workspace build. Bnd is the premiere tool for creating OSGi bundles. This Gradle plugin is from the team that develops Bnd and is used by the Bnd team to build Bnd itself. See https://github.com/bndtools/bnd/blob/${version}/gradle-plugins/README.md for information on using in a Bnd Workspace build."
}
create("BndBuilder") {
id = "biz.aQute.bnd.builder"
implementationClass = "aQute.bnd.gradle.BndBuilderPlugin"
displayName = "Bnd Gradle Plugin for Gradle Projects"
description = "Gradle Plugin for developing OSGi bundles with Bnd in a typical Gradle build. Bnd is the premiere tool for creating OSGi bundles. This Gradle plugin is from the team that develops Bnd. See https://github.com/bndtools/bnd/blob/${version}/gradle-plugins/README.md for information on using in a typical Gradle build."
}
create("BndWorkspace") {
id = "biz.aQute.bnd.workspace"
implementationClass = "aQute.bnd.gradle.BndWorkspacePlugin"
displayName = "Bnd Gradle Plugin for the Bnd Workspace"
description = "Gradle Plugin for developing OSGi bundles with Bnd using the Bnd Workspace build. Bnd is the premiere tool for creating OSGi bundles. This Gradle plugin is from the team that develops Bnd and is used by the Bnd team to build Bnd itself. See https://github.com/bndtools/bnd/blob/${version}/gradle-plugins/README.md for information on using on a Bnd Workspace."
}
}
}
// Gradle plugin bundle description
pluginBundle {
website = "https://github.com/bndtools/bnd"
vcsUrl = "https://github.com/bndtools/bnd.git"
description = "Gradle Plugins for developing OSGi bundles with Bnd. Bnd is the premiere tool for creating OSGi bundles. This gradle plugin is from the team that develops Bnd. See https://github.com/bndtools/bnd/blob/master/gradle-plugins/README.md."
tags = listOf("osgi", "bnd")
}
publishing {
repositories {
maven {
name = "Dist"
url = uri(rootProject.layout.projectDirectory).resolve(bnd_distrepo)
}
if (System.getenv("CANONICAL").toBoolean()) {
val releaseType = if (version.toString().endsWith("SNAPSHOT")) "snapshot" else "release"
maven {
name = "JFrog"
url = uri("https://bndtools.jfrog.io/bndtools/libs-${releaseType}-local/")
credentials {
username = System.getenv("JFROG_USERNAME") ?: ""
password = System.getenv("JFROG_PASSWORD") ?: ""
}
}
}
}
publications {
// Main plugin publication
create<MavenPublication>("pluginMaven") {
pom {
name.set(artifactId)
description.set("The Bnd Gradle plugins.")
}
}
// Configure pom metadata
withType<MavenPublication> {
pom {
url.set("https://bnd.bndtools.org/")
organization {
name.set("Bndtools")
url.set("https://bndtools.org/")
}
licenses {
license {
name.set("(Apache-2.0 OR EPL-2.0)")
url.set("https://opensource.org/licenses/Apache-2.0,https://opensource.org/licenses/EPL-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, or the Eclipse Public License 2.0.")
}
}
scm {
url.set("https://github.com/bndtools/bnd")
connection.set("scm:git:https://github.com/bndtools/bnd.git")
developerConnection.set("scm:git:git@github.com:bndtools/bnd.git")
tag.set(version.toString())
}
developers {
developer {
id.set("bjhargrave")
name.set("BJ Hargrave")
email.set("bj@hargrave.dev")
url.set("https://github.com/bjhargrave")
organization.set("IBM")
organizationUrl.set("https://developer.ibm.com")
roles.set(setOf("developer"))
timezone.set("America/New_York")
}
}
}
val publication = this
tasks.register<WriteProperties>("generatePomPropertiesFor${publication.name.capitalize()}Publication") {
description = "Generates the Maven pom.properties file for publication '${publication.name}'."
group = PublishingPlugin.PUBLISH_TASK_GROUP
setOutputFile(layout.buildDirectory.file("publications/${publication.name}/pom-default.properties"))
property("groupId", provider { publication.groupId })
property("artifactId", provider { publication.artifactId })
property("version", provider { publication.version })
}
}
}
}
// Handle JPMS options
val jpmsOptions: List<String>? by rootProject.extra
jpmsOptions?.let {
tasks.withType<GroovyCompile> {
groovyOptions.fork(mapOf("jvmArgs" to it))
}
}
// Disable gradle module metadata
tasks.withType<GenerateModuleMetadata> {
enabled = false
}
// Reproducible jars
tasks.withType<AbstractArchiveTask> {
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}
// Reproducible javadoc
tasks.withType<Javadoc> {
options {
this as StandardJavadocDocletOptions // unsafe cast
isNoTimestamp = true
}
}
tasks.pluginUnderTestMetadata {
// Include dsl SourceSet
pluginClasspath.from(sourceSets["dsl"].output)
}
tasks.jar {
// Include dsl SourceSet
from(sourceSets["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(sourceSets["dsl"].allSource)
}
// 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 testresources = layout.projectDirectory.dir("testresources")
val target = layout.buildDirectory.dir("testresources")
inputs.files(testresources).withPathSensitivity(PathSensitivity.RELATIVE).withPropertyName("testresources")
systemProperty("bnd_version", bnd_version)
systemProperty("org.gradle.warning.mode", gradle.startParameter.warningMode.name.toLowerCase())
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(target)
}
injected.fs.copy {
from(testresources)
into(target)
}
}
}
tasks.named<Delete>("cleanTest") {
val target = layout.buildDirectory.dir("testresources")
delete(target)
}