-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
236 lines (193 loc) · 8.07 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
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import java.net.URI
import kotlin.io.encoding.Base64.Default.decode
import kotlin.io.encoding.ExperimentalEncodingApi
plugins {
java
// IntelliJ
idea
// Apply the Kotlin JVM plugin to add support for Kotlin on the JVM.
kotlin("jvm")
// Classes annotated with @Configuration, @Controller, @RestController, @Service or @Repository are automatically opened
// https://kotlinlang.org/docs/reference/compiler-plugins.html#spring-support
kotlin("plugin.spring")
kotlin("plugin.jpa")
kotlin("plugin.allopen")
// Allows to package executable jar or war archives, run Spring Boot applications,
// and use the dependency management
// https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/
id("org.springframework.boot")
// A Gradle plugin that provides Maven-like dependency management and exclusions
// https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/
id("io.spring.dependency-management")
// For dependency version upgrades "gradle dependencyUpdates -Drevision=release"
id("com.github.ben-manes.versions")
// Checkstyle
id("org.jlleitschuh.gradle.ktlint")
id("com.diffplug.spotless")
// Docker-compose plugin
id("com.avast.gradle.docker-compose")
id("com.github.jk1.dependency-license-report") version "2.9"
id("org.jetbrains.dokka")
id("org.owasp.dependencycheck") version "11.1.1"
`maven-publish`
`signing`
}
allprojects {
repositories {
mavenCentral()
maven(URI("https://repository.jboss.org/nexus/content/repositories/releases"))
maven(URI("https://oss.sonatype.org/content/repositories/releases"))
maven(URI("https://app.camunda.com/nexus/content/groups/public"))
maven(URI("https://s01.oss.sonatype.org/content/groups/staging/"))
maven(URI("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
subprojects {
println("Enabling com.avast.gradle.docker-compose plugin in project ${project.name}...")
apply(plugin = "com.avast.gradle.docker-compose")
println("Enabling org.jlleitschuh.gradle.ktlint plugin in project ${project.name}...")
apply(plugin = "org.jlleitschuh.gradle.ktlint")
println("Enabling com.diffplug.spotless plugin in project ${project.name}...")
apply(plugin = "com.diffplug.spotless")
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "java")
apply(plugin = "maven-publish")
var signingConfigSet = false
if (System.getenv("SIGNING_KEY") != null &&
System.getenv("SIGNING_KEY_PASSWORD") != null
) {
signingConfigSet = true
apply(plugin = "signing")
}
if (project.properties.containsKey("isLib") || project.properties.containsKey("isApp")) {
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
kotlin {
// by default the target is every '.kt' and '.kts` file in the java sourcesets
licenseHeaderFile("licenseHeaderFile.template") // or licenseHeaderFile.template
}
kotlinGradle {
target("*.gradle.kts") // default target for kotlinGradle
}
}
}
java {
withSourcesJar()
withJavadocJar()
}
if (!(project.path.contains("gradle"))) {
println("Enabling Spring Boot plugin in project ${project.name}...")
apply(plugin = "org.springframework.boot")
}
println("Enabling Kotlin Spring plugin in project ${project.name}...")
apply(plugin = "org.jetbrains.kotlin.plugin.spring")
println("Enabling Kotlin JPA plugin in project ${project.name}...")
apply(plugin = "org.jetbrains.kotlin.plugin.jpa")
println("Enabling Kotlin All-open plugin in project ${project.name}...")
apply(plugin = "org.jetbrains.kotlin.plugin.allopen")
tasks.withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
freeCompilerArgs.add("-Xjsr305=strict")
freeCompilerArgs.add("-Xemit-jvm-type-annotations")
}
}
println("Enabling Spring Boot Dependency Management in project ${project.name}...")
apply(plugin = "io.spring.dependency-management")
configure<DependencyManagementExtension> {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) {
bomProperty("graphql-java.version", ApiVersions.graphqlJava)
}
}
}
tasks.withType<Test> {
useJUnitPlatform()
}
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/nl-portal/nl-portal-backend-libraries")
credentials {
username = System.getenv("USER")
password = System.getenv("TOKEN")
}
}
maven {
name = "Sonatype"
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
var stagingRepoUrl = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
if (version.toString().matches("^(\\d+\\.)?(\\d+\\.)?(\\d+)\$".toRegex())) {
url = stagingRepoUrl
}
}
maven {
name = "SonatypeSnapshot"
credentials {
username = System.getenv("OSSRH_USERNAME")
password = System.getenv("OSSRH_TOKEN")
}
var snapshotsRepoUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
if (version.toString().endsWith("SNAPSHOT")) {
url = snapshotsRepoUrl
}
}
}
publications {
register<MavenPublication>("default") {
groupId = "nl.nl-portal"
pom {
url = "https://github.com/nl-portal/nl-portal-backend-libraries"
licenses {
license {
name = "Licensed under EUPL, Version 1.2 (the \"License\");"
url = "https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12"
}
}
scm {
connection = "[email protected]:nl-portal/nl-portal-backend-libraries.git"
developerConnection = "[email protected]:nl-portal/nl-portal-backend-libraries.git"
url = "https://github.com/nl-portal/nl-portal-backend-libraries"
}
}
from(components["java"])
}
}
}
if (signingConfigSet) {
signing {
val signingKeyBase64: String? = System.getenv("SIGNING_KEY")
val signingKeyBytes: ByteArray = getSigningKey(signingKeyBase64!!)
val signingKey: String = signingKeyBytes.toString(Charsets.UTF_8)
val signingKeyPassword: String? = System.getenv("SIGNING_KEY_PASSWORD")
useInMemoryPgpKeys(signingKey, signingKeyPassword)
sign(publishing.publications["default"])
}
}
}
tasks.register<HtmlDependencyReportTask>("htmlDependencyReport")
tasks.named<HtmlDependencyReportTask>("htmlDependencyReport") {
projects = project.allprojects
reports.html.outputLocation = file("build/reports/project/dependencies")
}
tasks.bootJar {
enabled = false
}
@OptIn(ExperimentalEncodingApi::class)
fun getSigningKey(signingKeyBase64: String): ByteArray {
return decode(signingKeyBase64.subSequence(0, signingKeyBase64.length))
}
tasks.withType<PublishToMavenRepository> {
enabled = false
}
tasks.withType<PublishToMavenLocal> {
enabled = false
}
// println("Apply deployment script")
// apply(from = "gradle/deployment.gradle")