forked from navikt/helse-sparkelapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
183 lines (156 loc) · 5.83 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
import com.fasterxml.jackson.databind.ObjectMapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val jvmTarget = "17"
plugins {
kotlin("jvm") version "1.7.0"
}
val gradleWrapperVersion = "7.4.2"
val junitJupiterVersion = "5.8.2"
val rapidsAndRiversVersion = "2022122313141671797650.f806f770805a"
val ktorVersion = "2.1.1"
val cxfVersion = "3.5.3"
val mockkVersion = "1.12.0"
val wiremockVersion = "2.27.2"
buildscript {
repositories { mavenCentral() }
dependencies { "classpath"(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = "2.13.2.2") }
}
val mapper = ObjectMapper()
fun getBuildableProjects(): List<Project> {
val changedFiles = System.getenv("CHANGED_FILES")?.split(",") ?: emptyList()
val commonChanges = changedFiles.any {
it.startsWith("felles/") || it.contains("config/nais.yml")
|| it.startsWith("build.gradle.kts")
|| it == ".github/workflows/build.yml"
|| it == "Dockerfile"
|| it == "settings.gradle.kts"
}
if (changedFiles.isEmpty() || commonChanges) return subprojects.toList()
return subprojects.filter { project -> changedFiles.any { path -> path.contains("${project.name}/") } }
}
fun getDeployableProjects() = getBuildableProjects()
.filter { project -> File("config", project.name).isDirectory }
tasks.create("buildMatrix") {
doLast {
println(mapper.writeValueAsString(mapOf(
"project" to getBuildableProjects().map { it.name }
)))
}
}
tasks.create("deployMatrix") {
doLast {
// map of cluster to list of apps
val deployableProjects = getDeployableProjects().map { it.name }
val environments = deployableProjects
.map { project ->
project to (File("config", project)
.listFiles()
?.filter { it.isFile && it.name.endsWith(".yml") }
?.filterNot { it.name.contains("aiven") }
?.map { it.name.removeSuffix(".yml") }
?: emptyList())
}.toMap()
val clusters = environments.flatMap { it.value }.distinct()
val exclusions = environments
.mapValues { (_, configs) ->
clusters.filterNot { it in configs }
}
.filterValues { it.isNotEmpty() }
.flatMap { (app, clusters) ->
clusters.map { cluster -> mapOf(
"project" to app,
"cluster" to cluster
)}
}
println(mapper.writeValueAsString(mapOf(
"cluster" to clusters,
"project" to deployableProjects,
"exclude" to exclusions
)))
}
}
allprojects {
group = "no.nav.helse.sparkel"
version = properties["version"] ?: "local-build"
apply(plugin = "org.jetbrains.kotlin.jvm")
dependencies {
if (!erFellesmodul()) implementation(project(":felles"))
testImplementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
}
repositories {
val githubPassword: String by project
maven("https://packages.confluent.io/maven/")
maven("https://oss.sonatype.org")
mavenCentral()
maven {
url = uri("https://maven.pkg.github.com/navikt/*")
credentials {
username = "x-access-token"
password = githubPassword
}
}
}
tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = jvmTarget
}
named<KotlinCompile>("compileTestKotlin") {
kotlinOptions.jvmTarget = jvmTarget
}
withType<Wrapper> {
gradleVersion = gradleWrapperVersion
}
withType<Test> {
useJUnitPlatform()
testLogging {
events("skipped", "failed")
}
}
}
}
subprojects {
ext {
set("ktorVersion", ktorVersion)
set("rapidsAndRiversVersion", rapidsAndRiversVersion)
set("cxfVersion", cxfVersion)
}
dependencies {
testImplementation("io.mockk:mockk:$mockkVersion")
testImplementation("com.github.tomakehurst:wiremock:$wiremockVersion") {
exclude(group = "junit")
exclude("com.github.jknack.handlebars.java")
}
testImplementation("io.ktor:ktor-client-mock-jvm:$ktorVersion")
}
tasks {
if (project.skalLagAppJar()) {
named<Jar>("jar") {
archiveBaseName.set("app")
val mainClass = project.mainClass()
doLast {
val mainClassFound = this.project.sourceSets.findByName("main")?.let {
it.output.classesDirs.asFileTree.any { it.path.contains(mainClass.replace(".", File.separator)) }
} ?: false
if (!mainClassFound) throw RuntimeException("Kunne ikke finne main class: $mainClass")
}
manifest {
attributes["Main-Class"] = mainClass
attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(separator = " ") { it.name }
}
doLast {
configurations.runtimeClasspath.get().forEach {
val file = File("$buildDir/libs/${it.name}")
if (!file.exists())
it.copyTo(file)
}
}
}
}
}
}
fun Project.mainClass() =
"$group.${name.replace("-", "")}.AppKt"
fun Project.erFellesmodul() = name == "felles"
fun Project.skalLagAppJar() = name !in listOf("felles", "abakus")