-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.gradle.kts
278 lines (254 loc) · 8.18 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
import io.freefair.gradle.plugins.maven.central.ValidateMavenPom
import java.text.SimpleDateFormat
import java.util.*
plugins {
id("groovy")
id("java-gradle-plugin")
id("maven-publish")
id("signing")
id("com.github.ben-manes.versions") version "0.51.0"
id("net.ossindex.audit") version "0.4.11"
id("com.gradle.plugin-publish") version "1.3.0"
id("io.github.gradle-nexus.publish-plugin") version "2.0.0"
id("io.freefair.maven-central.validate-poms") version "8.10"
}
val dependencyVersions = listOf<String>(
)
repositories {
mavenCentral()
}
configurations.all {
resolutionStrategy {
failOnVersionConflict()
force(dependencyVersions)
}
}
dependencies {
constraints {
listOf(
"org.apache.maven:maven-artifact",
"org.apache.maven:maven-core",
"org.apache.maven:maven-model",
"org.apache.maven:maven-plugin-api",
).forEach {
implementation(it) {
version {
strictly("[3,)")
prefer("3.8.5")
}
}
}
listOf(
"org.apache.maven:maven-archiver",
).forEach {
implementation(it) {
version {
strictly("[3,)")
prefer("3.5.1")
}
}
}
implementation("org.apache.maven.shared:maven-shared-utils") {
version {
strictly("[3,)")
prefer("3.3.4")
}
}
implementation("org.apache.commons:commons-compress") {
version {
strictly("[1.20,)")
prefer("1.27.0")
}
}
implementation("commons-io:commons-io") {
version {
strictly("[2,3)")
prefer("2.16.1")
}
}
implementation("org.codehaus.plexus:plexus-classworlds") {
version {
strictly("[2.5,)")
prefer("2.6.0")
}
}
implementation("org.codehaus.plexus:plexus-component-annotations") {
version {
strictly("[2,)")
prefer("2.1.0")
}
}
implementation("org.codehaus.plexus:plexus-utils") {
version {
strictly("[3,)")
prefer("3.4.1")
}
}
implementation("org.slf4j:slf4j-api") {
version {
strictly("[1.7,)")
prefer("1.7.36")
}
}
}
api(gradleApi())
api(localGroovy())
api("org.vafer:jdeb:1.11")
implementation("org.apache.commons:commons-compress:1.27.0")
implementation("commons-io:commons-io:2.16.1")
testImplementation("org.spockframework:spock-core:2.3-groovy-3.0")
testImplementation("cglib:cglib-nodep:3.3.0")
// see https://docs.gradle.org/current/userguide/test_kit.html
//testImplementation(gradleTestKit())
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
tasks {
withType(Test::class.java) {
useJUnitPlatform()
}
}
val javadocJar by tasks.registering(Jar::class) {
dependsOn("classes")
archiveClassifier.set("javadoc")
from(tasks.javadoc)
}
val sourcesJar by tasks.registering(Jar::class) {
dependsOn("classes")
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
artifacts {
add("archives", sourcesJar.get())
add("archives", javadocJar.get())
}
fun findProperty(s: String) = project.findProperty(s) as String?
val localRepositoryName = "LocalPackages"
val gitHubPackagesRepositoryName = "GitHubPackages"
val isSnapshot = project.version == "unspecified"
val artifactVersion = if (!isSnapshot) project.version as String else SimpleDateFormat("yyyy-MM-dd\'T\'HH-mm-ss").format(Date())!!
val publicationName = "gradleDebianPlugin"
publishing {
repositories {
maven {
name = localRepositoryName
url = uri("../local-plugins")
}
maven {
name = gitHubPackagesRepositoryName
url = uri("https://maven.pkg.github.com/${property("github.package-registry.owner")}/${property("github.package-registry.repository")}")
credentials {
username = System.getenv("GITHUB_ACTOR") ?: findProperty("github.package-registry.username")
password = System.getenv("GITHUB_TOKEN") ?: findProperty("github.package-registry.password")
}
}
}
publications {
register<MavenPublication>(publicationName) {
pom {
name.set("gradle-debian-plugin")
description.set("A Debian plugin for Gradle")
url.set("https://github.com/gesellix/gradle-debian-plugin")
licenses {
license {
name.set("MIT")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("gesellix")
name.set("Tobias Gesellchen")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:github.com/gesellix/gradle-debian-plugin.git")
developerConnection.set("scm:git:ssh://github.com/gesellix/gradle-debian-plugin.git")
url.set("https://github.com/gesellix/gradle-debian-plugin")
}
}
artifactId = "gradle-debian-plugin"
version = artifactVersion
from(components["java"])
// TODO how do we ensure that these artifacts will always be added
// automatically?
// artifact(sourcesJar.get())
// artifact(javadocJar.get())
}
}
}
nexusPublishing {
repositories {
if (!isSnapshot) {
sonatype {
// 'sonatype' is pre-configured for Sonatype Nexus (OSSRH) which is used for The Central Repository
stagingProfileId.set(System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: findProperty("sonatype.staging.profile.id")) //can reduce execution time by even 10 seconds
username.set(System.getenv("SONATYPE_USERNAME") ?: findProperty("sonatype.username"))
password.set(System.getenv("SONATYPE_PASSWORD") ?: findProperty("sonatype.password"))
}
}
}
}
signing {
setRequired({ !isSnapshot })
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications[publicationName])
}
gradlePlugin {
website.set("https://github.com/gesellix/gradle-debian-plugin")
vcsUrl.set("https://github.com/gesellix/gradle-debian-plugin.git")
plugins {
register(publicationName) {
id = "de.gesellix.debian"
displayName = "Gradle Debian plugin"
description = "Create Debian packages with Gradle"
implementationClass = "de.gesellix.gradle.debian.DebianPackagePlugin"
version = artifactVersion
tags.set(listOf("debian", "jdeb", "package", "ubuntu"))
}
}
}
tasks.withType<ValidateMavenPom>().configureEach {
ignoreFailures = System.getenv()["IGNORE_INVALID_POMS"] == "true"
|| name.contains("For${publicationName.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}PluginMarkerMaven")
|| name.contains("ForPluginMavenPublication")
}
tasks.register("publishTo${localRepositoryName}") {
group = "publishing"
description = "Publishes all Maven publications to the $localRepositoryName Maven repository."
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
it.repository == publishing.repositories[localRepositoryName]
})
}
tasks.register("publishTo${gitHubPackagesRepositoryName}") {
group = "publishing"
description = "Publishes all Maven publications to the $gitHubPackagesRepositoryName Maven repository."
dependsOn(tasks.withType<PublishToMavenRepository>().matching {
it.repository == publishing.repositories[gitHubPackagesRepositoryName]
})
}
val isLocalRepo = { repository: MavenArtifactRepository ->
repository == publishing.repositories[localRepositoryName]
}
val isStandardMavenPublication = { repository: MavenArtifactRepository, publication: MavenPublication ->
publication == publishing.publications[publicationName]
&& repository.name in listOf("sonatype", localRepositoryName, gitHubPackagesRepositoryName)
}
val isGradlePluginPublish = { repository: MavenArtifactRepository, publication: MavenPublication ->
publication == publishing.publications["pluginMaven"]
&& repository.name !in listOf("sonatype", localRepositoryName, gitHubPackagesRepositoryName)
}
tasks.withType<PublishToMavenRepository>().configureEach {
onlyIf {
isLocalRepo(repository)
|| isStandardMavenPublication(repository, publication)
|| isGradlePluginPublish(repository, publication)
}
mustRunAfter(tasks.withType<Sign>())
}