-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathbuild.gradle
More file actions
504 lines (440 loc) · 18.3 KB
/
Copy pathbuild.gradle
File metadata and controls
504 lines (440 loc) · 18.3 KB
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
buildscript {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
plugins {
id 'java'
id 'jacoco-report-aggregation'
alias(libs.plugins.gradle.versions)
alias(libs.plugins.sonar)
alias(libs.plugins.jreleaser)
id 'com.dorongold.task-tree' version '4.0.1'
id 'me.qoomon.git-versioning' version '6.4.4'
}
allprojects {
group = group
version = htmlSanityCheckVersion
// Derive the version from the current Git ref so feature/bugfix branches publish under their own
// -SNAPSHOT coordinate and don't collide with each other or with release versions on GitHub Packages.
// Tags shaped 'v<version>' produce a release version; any other ref falls back to gradle.properties.
gitVersioning.apply {
refs {
branch('^(feature|bugfix)/.+') {
version = '${ref}-SNAPSHOT'
}
tag('v(?<version>.*)') {
version = '${ref.version}'
}
}
rev {
// Use Groovy interpolation (double quotes) so the gradle.properties value is captured
// at config time. git-versioning only substitutes its own placeholders (${ref},
// ${commit}, ...) and would otherwise pass the single-quoted literal as the version,
// which leaks into the published POM as "${htmlSanityCheckVersion}".
version = "${htmlSanityCheckVersion}"
}
}
repositories {
mavenCentral()
mavenLocal()
}
tasks.register("info") {
doLast
{
println "project.name : " + project.name
println "version : " + version
println "project.version : " + project.version
println "project.path : " + project.path
println "projectDir : " + projectDir
println "groupId : " + project.group
println "targetCompatibility : " + java.targetCompatibility
println "OS : " + System.properties["os.name"]
println "Java VM Name : " + System.properties["java.vm.name"]
println "Java VM Vendor : " + System.properties["java.vm.vendor"]
println "Java VM Version : " + System.properties["java.vm.version"]
println "=" * 80
}
}
}
// Single-line `./gradlew -q printVersion` returns the git-versioning–derived project.version.
// Used by generate-pages (and any shell caller) to propagate the dynamic version to standalone
// sub-builds like self-check that read htmlSanityCheckVersion from gradle.properties.
tasks.register("printVersion") {
doLast { println project.version }
}
dependencies {
// Add all subprojects to the aggregation
subprojects.forEach {
jacocoAggregation it
}
}
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport)
}
}
tasks.named('check') {
dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}
ext.urls = [
website : "https://hsc.aim42.org/",
issueTracker : 'https://github.com/aim42/htmlSanityCheck/issues',
scm : 'https://github.com/aim42/htmlSanityCheck.git',
connection : 'scm:git:git://github.com/aim42/htmlSanityCheck.git',
developerConnection: 'scm:git:ssh://github.com/aim42/htmlSanityCheck.git'
]
File baseBuildDir = file("${project.rootDir}/${Project.DEFAULT_BUILD_DIR_NAME}")
File mavenBuildRepo = new File(baseBuildDir, "maven-repo")
tasks.register("cleanMavenBuildRepo", Delete) {
description "Clean intermediate local Maven Repository '${mavenBuildRepo}'"
delete mavenBuildRepo
}
File mavenStagingRepo = new File(baseBuildDir, "staging-repo")
tasks.register("cleanMavenStagingRepo", Delete) {
description "Clean intermediate staging Maven Repository '${mavenStagingRepo}'"
delete mavenBuildRepo
}
tasks.register("copyOrgAim42ToStagingRepo", Copy) {
description = "Copy 'org/aim42' from '${mavenBuildRepo}; to '${mavenStagingRepo}'"
from new File(mavenBuildRepo, "org/aim42")
into new File(mavenStagingRepo, "org/aim42")
}
copyOrgAim42ToStagingRepo.dependsOn(
':htmlSanityCheck-core:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository',
':htmlSanityCheck-gradle-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository',
':htmlSanityCheck-maven-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository'
)
jreleaserRelease.dependsOn(
':htmlSanityCheck-cli:build',
copyOrgAim42ToStagingRepo,
)
jreleaser {
project {
license = 'Apache-2.0'
links {
homepage = urls.website
}
inceptionYear = '2014'
copyright = '2024'
authors = ['Gernot Starke', 'Gerd Aschemann']
}
release {
github {
repoOwner = 'aim42'
overwrite = true
tagName = '{{projectVersion}}'
changelog {
external = 'CHANGELOG.md'
}
prerelease {
enabled = true
pattern = '.*-rc\\d+$'
}
}
}
distributions {
hsc {
artifact {
path = 'htmlSanityCheck-cli/build/distributions/{{distributionName}}-{{projectVersion}}.zip'
}
artifact {
path = 'htmlSanityCheck-cli/build/distributions/{{distributionName}}-{{projectVersion}}.tar'
}
active = 'ALWAYS'
distributionType = 'JAVA_BINARY'
stereotype = 'CLI'
sdkman {
active = 'ALWAYS'
}
}
}
deploy {
active = 'NEVER'
maven {
mavenCentral {
app {
active = 'ALWAYS'
sign = false
url = 'https://central.sonatype.com/api/v1/publisher'
stagingRepository(mavenStagingRepo.toString())
}
}
}
}
announce {
active = 'ALWAYS'
mastodon {
active = 'ALWAYS'
host = 'https://mastodon.social'
statusTemplate = 'src/templates/jreleaser/mastodon.tpl'
}
}
packagers {
sdkman {
active = 'ALWAYS'
candidate = 'hsc'
command = 'MAJOR'
}
}
}
configure(subprojects) {
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'jacoco'
apply plugin: 'signing'
description "${rootProject.description} - Module ${project.name}"
dependencies {
implementation platform(libs.slf4j.bom)
testImplementation platform(libs.spock)
testImplementation "org.spockframework:spock-core"
testImplementation "org.spockframework:spock-junit4"
testImplementation libs.junit.vintage
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
withSourcesJar()
}
publishing {
publications.all { publication ->
if (publication instanceof MavenPublication) {
// GA coordinates must be lowercase (Maven convention, enforced by GitHub Packages).
// Each subproject sets base.archivesName explicitly to its lowercase artifactId.
artifactId = project.base.archivesName.get()
publication.pom {
name = project.name
description = project.description
url = urls.website
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'gstarke'
name = 'Gernot Starke'
email = 'gs@gernotstarke.de'
}
developer {
id = 'ascheman'
name = 'Gerd Aschemann'
email = 'gerd@aschemann.net'
}
developer {
id = 'rdmueller'
name = 'Ralf D. Müller'
email = 'ralf.d.mueller@gmail.com'
}
developer {
id = 'ruhrotht'
name = 'Thomas Ruhroth'
email = 'Thomas.Ruhroth@msg.group'
}
}
scm {
connection = urls.connection
developerConnection = urls.developerConnection
url = urls.scm
}
}
}
}
repositories {
maven {
name = 'myLocalRepositoryForFullIntegrationTests'
url = mavenBuildRepo
}
// Only register GitHubPackages when credentials are present. Otherwise Gradle's task-
// configuration validation fails for any publish task in the project with a cryptic
// "credentials.username doesn't have a configured value" — even for unrelated tasks.
// Skipping registration means trying to invoke publish*ToGitHubPackagesRepository
// without env vars yields a clear "task not found" instead.
if (System.getenv("GITHUB_USER") && System.getenv("GITHUB_TOKEN")) {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/aim42/htmlSanityCheck"
credentials {
username = System.getenv("GITHUB_USER")
password = System.getenv("GITHUB_TOKEN")
}
}
}
mavenLocal()
}
}
tasks.withType(PublishToMavenRepository).named { it.contains("MyLocalRepositoryForFullIntegrationTests") }.configureEach {
outputs.dir(mavenBuildRepo)
outputs.upToDateWhen { false }
}
// GitHub Packages rejects GETs to the plugin marker's snapshot maven-metadata.xml with
// HTTP 400, presumably because the marker artifactId 'org.aim42.htmlsanitycheck.gradle.plugin'
// contains dots that GH's package URL parser treats specially. Skip publishing the marker
// to GitHub Packages; consumers can still resolve it through the Gradle Plugin Portal once
// a release is cut. Local + Maven Central publish targets keep the marker.
tasks.withType(PublishToMavenRepository).configureEach {
if (name.endsWith("PluginMarkerMavenPublicationToGitHubPackagesRepository")) {
enabled = false
}
}
tasks.named('test', Test) {
useJUnitPlatform()
}
check {
finalizedBy jacocoTestReport // report is always generated after tests run
}
jacocoTestReport {
reports {
xml.required = true
}
dependsOn check // tests are required to run before generating the report
}
signing {
required = { project.hasProperty('enableSigning') && project.property('enableSigning') == 'true' }
if (project.hasProperty('useGpgCmd') && project.property('useGpgCmd') == 'true') {
useGpgCmd()
}
sign publishing.publications
}
}
def groovyVersion = GroovySystem.version
def groovyVersionMajorMinor = groovyVersion.split('\\.')[0..1].join('.')
tasks.named("dependencyUpdates").configure {
gradleReleaseChannel = true
resolutionStrategy {
componentSelection { rules ->
rules.all { ComponentSelection selection ->
if (selection.candidate.version =~ /(alpha|M)/) {
selection.reject('Rejected alpha or milestone version')
} else if (selection.candidate.group == 'org.spockframework') {
def spockGroovyVersion = selection.candidate.version.split('-')[2]
if (spockGroovyVersion != groovyVersionMajorMinor) {
selection.reject("Spock's Groovy version ($spockGroovyVersion) does not match project's Groovy major/minor version ($groovyVersionMajorMinor)")
}
} else if (selection.candidate.group == 'org.codehaus.groovy') {
if (selection.candidate.version != groovyVersion) {
selection.reject("Groovy version is determined by Gradle API (${groovyVersion})")
}
}
}
}
}
}
sonar {
properties {
property "sonar.projectKey", System.getenv("SONAR_PROJECT_KEY") ?: "aim42_htmlSanityCheck"
property "sonar.organization", System.getenv('SONAR_ORGANIZATION') ?: "aim42"
property "sonar.host.url", System.getenv('SONAR_URL') ?: "https://sonarcloud.io"
property "sonar.scm.provider", "git"
property "sonar.coverage.jacoco.xmlReportPaths", "**/build/reports/jacoco/test/jacocoTestReport.xml"
property "sonar.buildbreaker.skip", "false"
property "sonar.qualitygate.wait", true
// Default sonar.branch.name to the current git branch so local `./gradlew sonar`
// analyses land on the branch you're on, not the project's main branch.
// CI keeps overriding via -Psonar.branch.name=<ref>; that takes precedence via
// findProperty(). On detached HEAD (no detectable branch) we leave it unset and
// SonarCloud falls back to the project's configured main branch.
if (!findProperty("sonar.branch.name")) {
def envBranch = System.getenv("GITHUB_REF_NAME") ?: System.getenv("GITHUB_HEAD_REF")
def gitBranch = providers.exec {
commandLine 'git', 'rev-parse', '--abbrev-ref', 'HEAD'
}.standardOutput.asText.map { it.trim() }.getOrElse('')
def branch = (envBranch && envBranch != 'HEAD') ? envBranch
: (gitBranch && gitBranch != 'HEAD') ? gitBranch
: null
if (branch) {
property "sonar.branch.name", branch
}
}
}
}
tasks.register("publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository") {
group("Publishing")
description("Publishes all publications to the local Maven integration (test) repository")
dependsOn(
// For some reason it is necessary to add this task explicitly though it should be part of the
// ":htmlSanityCheck-gradle-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository" task
":htmlSanityCheck-gradle-plugin:publishHtmlSanityCheckPluginMarkerMavenPublicationToMyLocalRepositoryForFullIntegrationTestsRepository",
":htmlSanityCheck-core:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository",
":htmlSanityCheck-gradle-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository",
":htmlSanityCheck-maven-plugin:publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository",
)
}
final String INTEGRATION_TEST_DIRECTORY = "integration-test"
tasks.register("integrationTestOnly") {
group("Verification")
description("Perform all Integration Tests (Only)")
dependsOn(
':publishAllPublicationsToMyLocalRepositoryForFullIntegrationTestsRepository',
':htmlSanityCheck-cli:installDist',
)
doLast {
def result = exec {
workingDir INTEGRATION_TEST_DIRECTORY
commandLine((System.getProperty("os.name") ==~ /Windows.*/
? "..\\gradlew.bat"
: "../gradlew"),
"integrationTest",
// Forward the git-versioning–derived project.version to the child build so it
// can locate the just-published artifact in build/maven-repo.
"-PhtmlSanityCheckVersion=${project.version}",
)
}
logger.debug "Script output: ${result}"
}
}
tasks.register("cleanIntegrationTest", Delete) {
group("Build")
description("Perform clean for Integration Tests")
doLast {
def result = exec {
workingDir INTEGRATION_TEST_DIRECTORY
commandLine((System.getProperty("os.name") ==~ /Windows.*/
? "..\\gradlew.bat"
: "../gradlew"),
"clean")
}
logger.debug "Script output: ${result}"
}
}
clean.dependsOn(cleanIntegrationTest)
tasks.register("integrationTest") {
group("Verification")
description("Run overall integration tests (and publish/install first)")
dependsOn(
'integrationTestOnly',
)
}
/*
* Copyright Gernot Starke and aim42 contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/