-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
231 lines (199 loc) · 7.58 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
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
import org.gradle.api.tasks.testing.logging.TestLogEvent.STANDARD_ERROR
import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
import org.gradle.internal.logging.text.StyledTextOutput
import org.gradle.internal.logging.text.StyledTextOutput.Style
import org.gradle.internal.logging.text.StyledTextOutputFactory
import org.gradle.kotlin.dsl.support.serviceOf
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.getKotlinPluginVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.regex.Matcher
plugins {
kotlin("jvm")
id("java-gradle-plugin")
id("jacoco")
id("maven-publish")
id("net.researchgate.release")
id("com.gradle.plugin-publish")
}
group = "io.opengood.gradle"
gradlePlugin {
website.set("https://opengood.io")
vcsUrl.set("https://github.com/opengoodio/config-gradle-plugin")
plugins {
create("opengood-settings") {
id = "io.opengood.gradle.settings"
displayName = "OpenGood Settings Gradle Plugin"
description = "Gradle plugin providing centralized settings of OpenGood Gradle projects"
tags.set(listOf("kotlin", "spring-boot", "opengood"))
implementationClass = "io.opengood.gradle.SettingsPlugin"
}
}
}
val kotlinVersion = getKotlinPluginVersion()
val javaVersion = JavaVersion.VERSION_21
val jvmTargetVersion = JvmTarget.JVM_21
java.apply {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.jetbrains.kotlin") {
useVersion(kotlinVersion)
because("Incompatibilities with older Kotlin versions")
}
}
}
repositories {
mavenCentral()
gradlePluginPortal()
mavenLocal()
}
dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("allopen:_"))
implementation(kotlin("noarg:_"))
implementation(kotlin("gradle-plugin:_"))
implementation(gradleApi())
implementation("de.fayard.refreshVersions:refreshVersions:_")
implementation("com.fasterxml.jackson.core:jackson-annotations:_")
testImplementation(kotlin("test"))
testImplementation("io.kotest:kotest-assertions-core:_")
testImplementation("io.kotest:kotest-extensions-junit5:_")
testImplementation("io.kotest:kotest-property:_")
testImplementation("io.kotest:kotest-runner-junit5:_")
testImplementation("io.mockk:mockk:_")
}
val out: StyledTextOutput = project.serviceOf<StyledTextOutputFactory>().create("colored-output")
with(tasks) {
withType<Wrapper> {
distributionType = DistributionType.ALL
}
withType<KotlinCompile> {
withType<KotlinCompile> {
compilerOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget.set(jvmTargetVersion)
}
}
}
withType<Test> {
useJUnitPlatform()
finalizedBy("jacocoTestReport")
testLogging {
events = setOf(PASSED, SKIPPED, FAILED, STANDARD_ERROR)
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
}
maxParallelForks = Runtime.getRuntime().availableProcessors() / 2 + 1
systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_class")
doFirst {
with(out.style(Style.ProgressStatus)) {
println("***************************************************")
println(" >> Running Tests")
println("***************************************************")
}
}
addTestListener(
object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(
testDescriptor: TestDescriptor,
result: TestResult,
) {}
override fun afterSuite(
suite: TestDescriptor,
result: TestResult,
) {
if (suite.parent == null) {
val output =
"Results: ${result.resultType} " +
"(" +
"${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped" +
")"
val startItem = "| "
val endItem = " |"
val repeatLength = startItem.length + output.length + endItem.length
out.style(if (result.failedTestCount == 0L) Style.SuccessHeader else Style.FailureHeader).println(
"""
|
|${"-".repeat(repeatLength)}
|$startItem$output$endItem
|${"-".repeat(repeatLength)}
|
""".trimMargin(),
)
}
}
},
)
doLast {
with(out.style(Style.ProgressStatus)) {
println("***************************************************")
println(" >> Tests FINISHED")
println("***************************************************")
}
}
}
jacocoTestReport {
reports {
xml.required.set(true)
html.required.set(false)
}
}
create("setupPublishPlugins") {
doLast {
val publishKey = System.getenv("GRADLE_PUBLISH_KEY")
val publishSecret = System.getenv("GRADLE_PUBLISH_SECRET")
if (publishKey.isNotBlank() && publishSecret.isNotBlank()) {
println("Environment variables GRADLE_PUBLISH_KEY and GRADLE_PUBLISH_SECRET are set")
println("Using in-memory Gradle key and secret for plugin publishing")
} else {
println("Environment variables GRADLE_PUBLISH_KEY and GRADLE_PUBLISH_SECRET are not set")
println("Defaulting to global Gradle properties file for plugin publishing")
}
System.setProperty("gradle.publish.key", publishKey)
System.setProperty("gradle.publish.secret", publishSecret)
}
}
getByName("release") {
dependsOn("setupPublishPlugins")
}
getByName("afterReleaseBuild") {
dependsOn("publishPlugins")
}
}
release {
preTagCommitMessage.set("[Gradle Release] - pre tag commit: ")
newVersionCommitMessage.set("[Gradle Release] - new version commit: ")
versionPatterns =
mapOf(
"""[.]*\.(\d+)\.(\d+)[.]*""" to
KotlinClosure2<Matcher, Project, String>({ matcher, _ ->
matcher.replaceAll(".${(matcher.group(1)).toString().toInt() + 1}.0")
}),
)
git {
requireBranch.set("main")
pushToRemote.set("origin")
}
}
publishing {
repositories {
maven {
name = "local"
url = uri(mavenLocal().url)
}
}
}