forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbuild.gradle.kts
235 lines (215 loc) · 7.45 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
import okio.buffer
import okio.sink
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
import org.gradle.api.tasks.testing.logging.TestLogEvent
import java.nio.file.StandardOpenOption
buildscript {
dependencies {
classpath("com.squareup.okhttp3:okhttp:4.10.0")
}
}
plugins {
groovy
`maven-publish`
`kotlin-dsl`
signing
codenarc
id("com.gradle.plugin-publish") version "1.2.0"
`java-gradle-plugin`
id("com.github.sghill.distribution-sha") version "0.4.0"
id("nebula.release") version "19.0.10"
}
repositories {
maven {
url = uri("https://repo.jenkins-ci.org/public")
}
gradlePluginPortal()
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
dependencies {
compileOnly(libs.accessmodifier.checker)
annotationProcessor(libs.sezpoz)
implementation(gradleApi())
compileOnly(libs.jgit)
testImplementation(libs.jgit)
compileOnly(libs.javapoet) {
because("used for GenerateTestTask")
}
compileOnly(libs.jenkins.test.harness) {
because("used for GenerateTestTask")
isTransitive = false
}
compileOnly(libs.junit4) {
because("used for GenerateTest")
}
compileOnly(libs.localizer.maven)
implementation("com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.13")
implementation(libs.sezpoz)
implementation(localGroovy())
testAnnotationProcessor(libs.sezpoz)
testCompileOnly(libs.junit4) {
because("used for generated tests with javapoet")
}
testImplementation("org.spockframework:spock-core:2.1-groovy-3.0")
testImplementation(libs.xmlunit)
testImplementation(libs.commons.text)
testImplementation(libs.javapoet)
testImplementation(libs.accessmodifier.checker)
testImplementation(libs.jenkins.core) {
exclude(module = "groovy-all")
}
testImplementation(platform(libs.junit5.bom))
testImplementation(libs.junit5.api)
testImplementation(libs.assertj.core)
testRuntimeOnly(libs.junit5.jupiter)
testRuntimeOnly(libs.junit5.vintage)
}
publishing {
publications {
create<MavenPublication>("pluginMaven") {
pom {
name.set("Gradle JPI Plugin")
description.set("The Gradle JPI plugin is a Gradle plugin for building Jenkins plugins")
url.set("http://github.com/jenkinsci/gradle-jpi-plugin")
scm {
url.set("https://github.com/jenkinsci/gradle-jpi-plugin")
}
licenses {
license {
name.set("Apache 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("abayer")
name.set("Andrew Bayer")
}
developer {
id.set("kohsuke")
name.set("Kohsuke Kawaguchi")
}
developer {
id.set("daspilker")
name.set("Daniel Spilker")
}
developer {
id.set("sghill")
name.set("Steve Hill")
}
}
}
}
}
repositories {
maven {
val path = if (version.toString().endsWith("SNAPSHOT")) "snapshots" else "releases"
name = "JenkinsCommunity"
url = uri("https://repo.jenkins-ci.org/${path}")
credentials {
username = project.stringProp("jenkins.username")
password = project.stringProp("jenkins.password")
}
}
}
}
signing {
val signingKeyId: String? by project
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
setRequired { setOf("jenkins.username", "jenkins.password").all { project.hasProperty(it) } }
}
tasks.addRule("Pattern: testGradle<ID>") {
val taskName = this
if (!taskName.startsWith("testGradle")) return@addRule
val task = tasks.register(taskName)
for (javaVersion in listOf(11)) {
val javaSpecificTask = tasks.register<Test>("${taskName}onJava${javaVersion}") {
val gradleVersion = taskName.substringAfter("testGradle")
systemProperty("gradle.under.test", gradleVersion)
setTestNameIncludePatterns(listOf("*IntegrationSpec"))
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
})
}
task.configure {
dependsOn(javaSpecificTask)
}
}
}
val isCi = providers.environmentVariable("CI")
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
if (isCi.map { it.toBoolean() }.getOrElse(false)) {
events(TestLogEvent.FAILED, TestLogEvent.PASSED, TestLogEvent.SKIPPED)
}
exceptionFormat = FULL
}
}
codenarc {
toolVersion = "1.1"
configFile = rootProject.file("config/codenarc/rules.groovy")
}
tasks.codenarcTest {
configFile = rootProject.file("config/codenarc/rules-test.groovy")
}
group = "org.jenkins-ci.tools"
description = "Gradle plugin for building and packaging Jenkins plugins"
gradlePlugin {
plugins {
create("pluginMaven") {
id = "org.jenkins-ci.jpi"
implementationClass = "org.jenkinsci.gradle.plugins.jpi.JpiPlugin"
displayName = "A plugin for building Jenkins plugins"
}
}
}
pluginBundle {
website = "https://wiki.jenkins-ci.org/display/JENKINS/Gradle+JPI+Plugin"
vcsUrl = "https://github.com/jenkinsci/gradle-jpi-plugin"
description = "A plugin for building Jenkins plugins"
tags = listOf("jenkins")
}
fun Project.stringProp(named: String): String? = findProperty(named) as String?
tasks.register("shadeLatestVersionNumber") {
doLast {
val response = okhttp3.OkHttpClient().newCall(okhttp3.Request.Builder().get()
.url("https://raw.githubusercontent.com/jenkinsci/lib-version-number/master/src/main/java/hudson/util/VersionNumber.java")
.build())
.execute()
if (!response.isSuccessful) {
throw GradleException("${response.code} attempting to fetch latest hudson.util.VersionNumber")
}
val extension = project.extensions.getByType(JavaPluginExtension::class)
val main = extension.sourceSets.getByName("main")
val srcMainJava = main.java.srcDirs.single().toPath()
val dest = srcMainJava.resolve("shaded/hudson/util/VersionNumber.java")
val sink = dest.sink(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).buffer()
response.body?.use {
it.source().use { input ->
sink.use { output ->
output.writeAll(input)
}
}
}
}
}
val checkPhase = tasks.named("check")
val publishToJenkins = tasks.named("publishPluginMavenPublicationToJenkinsCommunityRepository")
publishToJenkins.configure {
dependsOn(checkPhase)
}
val publishToGradle = tasks.named("publishPlugins")
publishToGradle.configure {
dependsOn(checkPhase)
}
tasks.named("postRelease").configure {
dependsOn(publishToJenkins, publishToGradle)
}