This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
212 lines (203 loc) · 5.41 KB
/
build.gradle
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
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
plugins {
id 'version-catalog'
id 'test-report-aggregation'
id 'jacoco-report-aggregation'
id 'org.ajoberstar.reckon' version '0.16.1'
id 'org.sonarqube' version '3.4.0.2513'
id 'com.github.ben-manes.versions' version '0.42.0'
id 'org.asciidoctor.jvm.convert' version '3.3.2' apply false
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0' apply false
id 'me.filippov.gradle.jvm.wrapper' version '0.11.0'
}
tasks.named("dependencyUpdates").configure {
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { version.toUpperCase().contains(it) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
reckon {
scopeFromProp()
snapshotFromProp()
}
if (System.getenv('CI') == null) {
version = "0.0.0-SNAPSHOT"
}
task version {
doLast {
if (project.findProperty('reckon.stage')) {
println "to tag and release a new version '${version}' use:"
println "git tag -a '${version}' -m '${version}' && git push origin '${version}'"
} else {
println "current version is '${version}', to figure out the next version run:"
println "CI=true ./gradlew version -Preckon.stage=final -Preckon.scope=[major,minor,patch]"
}
}
}
reckonTagCreate.dependsOn "build"
allprojects {
repositories {
mavenCentral()
}
group 'ch.kk7'
version rootProject.version
}
// java defaults
subprojects {
apply plugin: 'java-library'
apply plugin: 'jacoco'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
}
consistentResolution {
useCompileClasspathVersions()
}
withSourcesJar()
withJavadocJar()
}
[11, 17].forEach(jv -> {
def testJava = tasks.register("testJava${jv}", Test) {
jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED'
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(jv)
}
shouldRunAfter 'test'
}
tasks.check.configure {
dependsOn testJava
}
})
tasks.withType(JavaCompile) {
options.incremental = true
}
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
configurations {
testOutput.extendsFrom testImplementation // reuse tests directly
compileOnly.extendsFrom annotationProcessor
testCompileOnly.extendsFrom compileOnly
testAnnotationProcessor.extendsFrom annotationProcessor
}
// must be disabled for `dependencyUpdates`: https://github.com/ben-manes/gradle-versions-plugin/issues/592
configurations.all {
resolutionStrategy {
failOnVersionConflict()
failOnNonReproducibleResolution()
}
}
dependencies {
annotationProcessor libs.autoservice
annotationProcessor libs.lombok
testImplementation libs.junit.params
testImplementation libs.junit.engine
testImplementation libs.assertj
testImplementation libs.systemlambda
testImplementation libs.awaitility
testRuntimeOnly libs.logback.classic
}
tasks.withType(Test) {
useJUnitPlatform() // junit5 support
if (System.getenv().containsKey("CI")) {
testLogging {
events "failed"
exceptionFormat "full"
}
}
}
}
// coverage
dependencies {
jacocoAggregation subprojects
}
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) {
testType = TestSuiteType.UNIT_TEST
}
}
}
sonarqube {
properties {
property 'sonar.host.url', 'https://sonarcloud.io'
property 'sonar.organization', 'keykey7-github'
property 'sonar.login', System.getenv('SONAR_TOKEN')
property 'sonar.coverage.jacoco.xmlReportPaths', tasks.testCodeCoverageReport.reports.xml.outputLocation.get()
}
}
// disable sonar analysis without secret (since secrets aren't availabe in PRs from forks)
tasks.sonarqube.enabled System.getenv('SONAR_TOKEN') != null
tasks.sonarqube.dependsOn tasks.testCodeCoverageReport
// releases
def isRemotePublish = System.getenv('CI') != null && System.getenv('SONATYPE_USERNAME') != null
if (isRemotePublish) {
logger.lifecycle("remote publishing is enabled")
apply plugin: 'io.github.gradle-nexus.publish-plugin'
nexusPublishing {
repositories {
sonatype {
username = System.getenv('SONATYPE_USERNAME')
password = System.getenv('SONATYPE_PASSWORD')
}
}
}
}
subprojects {
if (sourceSets.main.allSource.isEmpty()) {
return // excluding test-only subprojects
}
apply plugin: 'maven-publish'
publishing {
publications {
java(MavenPublication) {
from components.java
pom {
def githubUrl = "https://github.com/keykey7/confij"
name = project.name
description = "A type-safe, strongly defined Java configuration library"
url = githubUrl
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
scm {
connection = "scm:git:${githubUrl}.git"
developerConnection = "scm:git:${githubUrl}.git"
url = githubUrl
}
developers {
developer {
id = 'keykey7'
name = 'keykey7'
email = '[email protected]'
}
}
}
}
}
}
if (isRemotePublish) {
apply plugin: 'signing'
signing {
def signingKey = System.getenv('SONATYPE_SIGNKEY')
def signingPassword = System.getenv('SONATYPE_SIGNPASS')
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.java
}
}
}