forked from abayer/gradle-hpi-plugin
-
Notifications
You must be signed in to change notification settings - Fork 50
/
build.gradle.kts
205 lines (189 loc) · 6.75 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
import okio.buffer
import okio.sink
import org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
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.0.0"
`java-gradle-plugin`
id("com.github.sghill.distribution-sha") version "0.4.0"
}
plugins.apply(internal.DependenciesComparisonPlugin::class.java)
repositories {
maven {
url = uri("https://repo.jenkins-ci.org/public")
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
}
val sezpoz = "net.java.sezpoz:sezpoz:1.13"
dependencies {
compileOnly("org.kohsuke:access-modifier-checker:1.21")
annotationProcessor(sezpoz)
implementation(gradleApi())
compileOnly("com.squareup:javapoet:1.13.0") {
because("used for GenerateTestTask")
}
compileOnly("org.jenkins-ci.main:jenkins-test-harness:${stringProp("deps.jenkinsTestHarness")}") {
because("used for GenerateTestTask")
isTransitive = false
}
compileOnly("org.jvnet.localizer:maven-localizer-plugin:1.24")
implementation(sezpoz)
implementation(localGroovy())
testAnnotationProcessor(sezpoz)
testCompileOnly("junit:junit:4.13") {
because("used for generated tests with javapoet")
}
testImplementation("org.spockframework:spock-core:2.1-groovy-2.5")
testImplementation("org.xmlunit:xmlunit-core:2.8.3")
testImplementation("org.apache.commons:commons-text:1.10.0")
testImplementation("com.squareup:javapoet:1.13.0")
testImplementation("org.kohsuke:access-modifier-checker:1.21")
testImplementation("org.jenkins-ci.main:jenkins-core:2.263.3") {
exclude(module = "groovy-all")
}
testImplementation(platform("org.junit:junit-bom:5.8.1"))
testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.assertj:assertj-core:3.21.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
}
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 {
useGpgCmd()
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(8, 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)
}
}
}
tasks.withType<Test>().configureEach {
useJUnitPlatform()
testLogging {
exceptionFormat = FULL
}
}
codenarc {
toolVersion = "1.1"
configFile = file("config/codenarc/rules.groovy")
}
tasks.codenarcTest {
configFile = 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 convention = project.convention.getPlugin(JavaPluginConvention::class)
val main = convention.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)
}
}
}
}
}