-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
223 lines (203 loc) · 6.19 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
import com.vanniktech.maven.publish.SonatypeHost
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.kotlin.dsl.support.serviceOf
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.extraProperties
import java.io.ByteArrayOutputStream
import java.io.StringReader
import java.nio.charset.StandardCharsets
import java.util.Properties
group = "dev.codebandits"
val projectDescription = listOf(
"Container is a Gradle plugin that enhances build portability, reproducibility, and flexibility",
"by integrating containers into Gradle tasks. It provides a declarative and familiar way",
"to run task operations inside containers and declare containers as task inputs and outputs."
).joinToString(" ")
plugins {
alias(libs.plugins.kotlinJvm)
alias(libs.plugins.mavenPublish)
alias(libs.plugins.testRetry)
`java-gradle-plugin`
`jvm-test-suite`
signing
}
mavenPublishing {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
signAllPublications()
pom {
description = projectDescription
url = "https://github.com/codebandits/container-gradle-plugin"
licenses {
license {
name = "MIT License"
url = "https://github.com/codebandits/container-gradle-plugin/blob/main/LICENSE"
distribution = "repo"
}
}
developers {
developer {
id.set("codebandits")
name = "Code Bandits Team"
organization = "Code Bandits"
organizationUrl = "https://github.com/codebandits"
}
}
scm {
url = "https://github.com/codebandits/container-gradle-plugin"
}
}
}
tasks {
val configureSigning = register("configureSigning") {
group = "publishing"
doLast {
ByteArrayOutputStream()
.use { sopsOutputStream ->
serviceOf<ExecOperations>().exec {
commandLine("sh", "-c", "sops --decrypt signing.enc.properties")
standardOutput = sopsOutputStream
}
sopsOutputStream.toString(StandardCharsets.UTF_8)
}
.let { output -> Properties().apply { load(StringReader(output)) } }
.forEach { key, value -> project.extraProperties.set(key.toString(), value) }
signing.useInMemoryPgpKeys(
project.property("signing.keyId").toString(),
project.property("signing.key").toString(),
project.property("signing.password").toString(),
)
}
}
withType<Sign> {
dependsOn(configureSigning)
}
val loadPublishingSecrets = register("loadPublishingSecrets") {
group = "publishing"
doLast {
ByteArrayOutputStream()
.use { sopsOutputStream ->
serviceOf<ExecOperations>().exec {
commandLine("sh", "-c", "sops --decrypt publishing.enc.properties")
standardOutput = sopsOutputStream
}
sopsOutputStream.toString(StandardCharsets.UTF_8)
}
.let { output -> Properties().apply { load(StringReader(output)) } }
.forEach { key, value -> project.extraProperties.set(key.toString(), value) }
}
}
withType<PublishToMavenRepository> {
if (name.endsWith("ToMavenCentralRepository")) {
dependsOn(loadPublishingSecrets)
}
}
}
kotlin {
explicitApi()
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
java {
targetCompatibility = JavaVersion.VERSION_17
}
sourceSets {
create("testShared")
}
dependencies {
add(sourceSets["testShared"].apiConfigurationName, libs.junit.jupiter.api)
testImplementation(sourceSets["testShared"].output)
}
testing {
@Suppress("UnstableApiUsage")
suites {
register<JvmTestSuite>("testFeatures") {
dependencies {
implementation(project())
implementation(sourceSets["testShared"].output)
}
targets.all {
testTask {
shouldRunAfter("test")
}
}
}
register<JvmTestSuite>("testPlatforms") {
dependencies {
implementation(project())
implementation(sourceSets["testShared"].output)
implementation(libs.testcontainers.testcontainers)
}
targets.all {
testTask {
dependsOn("jar")
environment("PROJECT_ROOT", rootDir.absolutePath)
shouldRunAfter("test", "testFeatures")
retry {
if (System.getenv().containsKey("CI")) {
maxRetries = 3
}
}
}
}
}
register<JvmTestSuite>("testToolIntegrations") {
dependencies {
implementation(project())
implementation(sourceSets["testShared"].output)
}
targets.all {
testTask {
shouldRunAfter("test", "testFeatures")
}
}
}
withType<JvmTestSuite> {
useJUnitJupiter(libs.versions.junit.jupiter)
dependencies {
implementation(libs.strikt.core)
implementation.bundle(libs.bundles.logging.implementation)
runtimeOnly.bundle(libs.bundles.logging.runtime)
}
targets.all {
testTask {
doFirst { fixTestKitLoggingInterference() }
testLogging {
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
exceptionFormat = TestExceptionFormat.FULL
}
}
}
}
}
}
gradlePlugin {
plugins {
create("container") {
id = "dev.codebandits.container"
implementationClass = "dev.codebandits.container.gradle.plugin.ContainerPlugin"
}
}
testSourceSets(
sourceSets["testFeatures"],
sourceSets["testPlatforms"],
sourceSets["testToolIntegrations"],
)
}
tasks.named("check") {
@Suppress("UnstableApiUsage")
dependsOn(
testing.suites.named("testFeatures"),
testing.suites.named("testPlatforms"),
testing.suites.named("testToolIntegrations"),
)
}
// Workaround for https://github.com/gradle/gradle/issues/1893
// Inspired by https://github.com/ratpack/ratpack/commit/0d9d2eb1d863a2a80b06c3e37f90cad1e7c4bdd1
fun Test.fixTestKitLoggingInterference() {
val gradleTestKitFiles = (dependencies.gradleTestKit() as? FileCollectionDependency)?.files ?: emptySet()
classpath = files(classpath.files.sortedBy { it in gradleTestKitFiles })
}