-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
169 lines (145 loc) · 5.76 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
import com.fasterxml.jackson.databind.ObjectMapper
plugins {
kotlin("jvm") version "2.0.21"
}
val junitJupiterVersion = "5.11.3"
val rapidsAndRiversVersion = "2024120608421733470968.fc0a3d5e3685"
val ktorVersion = "3.0.1" // should be set to same value as rapids and rivers
val mockkVersion = "1.13.13"
val hikariCPVersion = "6.1.0"
val kotliqueryVersion = "1.9.0"
val postgresqlVersion = "42.7.4"
val flywayCoreVersion = "10.21.0"
val tbdLibsVersion = "2024.11.25-10.59-6f263a10"
buildscript {
repositories { mavenCentral() }
dependencies { "classpath"(group = "com.fasterxml.jackson.core", name = "jackson-databind", version = "2.16.1") }
}
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"
}
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.associateWith { project ->
(File("config", project)
.listFiles()
?.filter { it.isFile && it.name.endsWith(".yml") }
?.filterNot { it.name.contains("aiven") }
?.map { it.name.removeSuffix(".yml") }
?: emptyList())
}
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.spre"
version = properties["version"] ?: "local-build"
apply(plugin = "org.jetbrains.kotlin.jvm")
dependencies {
if (!erFellesmodul()) implementation(project(":felles"))
testImplementation("org.junit.jupiter:junit-jupiter:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}
repositories {
val githubPassword: String? by project
mavenCentral()
/* ihht. https://github.com/navikt/utvikling/blob/main/docs/teknisk/Konsumere%20biblioteker%20fra%20Github%20Package%20Registry.md
så plasseres github-maven-repo (med autentisering) før nav-mirror slik at github actions kan anvende førstnevnte.
Det er fordi nav-mirroret kjører i Google Cloud og da ville man ellers fått unødvendige utgifter til datatrafikk mellom Google Cloud og GitHub
*/
maven {
url = uri("https://maven.pkg.github.com/navikt/maven-release")
credentials {
username = "x-access-token"
password = githubPassword
}
}
maven("https://github-package-registry-mirror.gc.nav.no/cached/maven-release")
}
kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of("21"))
}
}
tasks {
withType<Test> {
useJUnitPlatform()
testLogging {
events("skipped", "failed")
}
}
}
}
subprojects {
ext {
set("ktorVersion", ktorVersion)
set("rapidsAndRiversVersion", rapidsAndRiversVersion)
set("mockkVersion", mockkVersion)
set("hikariCPVersion", hikariCPVersion)
set("kotliqueryVersion", kotliqueryVersion)
set("postgresqlVersion", postgresqlVersion)
set("flywayCoreVersion", flywayCoreVersion)
set("tbdLibsVersion", tbdLibsVersion)
}
tasks {
if (!project.erFellesmodul()) {
named<Jar>("jar") {
archiveBaseName.set("app")
val mainClass = project.mainClass()
doLast {
val mainClassFound = this.project.sourceSets.findByName("main")?.let { sourceSet ->
sourceSet.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("${layout.buildDirectory.get()}/libs/${it.name}")
if (!file.exists())
it.copyTo(file)
}
}
}
}
}
}
fun Project.mainClass() =
"$group.${name.replace("-", "")}.AppKt"
fun Project.erFellesmodul() = name == "felles"