-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbuild.gradle.kts
219 lines (189 loc) · 7.02 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
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
@file:Suppress("UnstableApiUsage")
import io.ktor.plugins.registry.*
val skipPlugins: String by project
val ktorReleases = getKtorReleases(logger)
val latestKtor = ktorReleases.last()
val pluginConfigs by lazy {
if (skipPlugins.toBoolean())
emptyList()
else collectPluginConfigs(logger, ktorReleases)
}
val mock = "mock"
// TODO KTOR-7849 need to introduce multi-platform compilation to get wasm-js modules to work properly
// but this will require a lot of changes here
fun List<PluginConfiguration>.skipWebModules() =
filterNot { it.module == ProjectModule.web }
plugins {
alias(libs.plugins.serialization)
alias(libs.plugins.jvm)
alias(libs.plugins.detekt)
}
group = "io.ktor"
version = "1.0-SNAPSHOT"
// create build config for each valid release-plugin-target triple
configurations {
// create mock configuration
create(mock) {}
// create plugin build configs
for (pluginConfig in pluginConfigs) {
create(pluginConfig.name) {
pluginConfig.parent?.let { parent ->
extendsFrom(get(parent))
}
}
}
}
repositories {
mavenCentral()
for (repositoryUrl in pluginConfigs.flatMap { it.repositories }.distinct()) {
maven(repositoryUrl)
}
}
sourceSets {
// mock for the expected generated project sources, so plugins can reference these
val mockSourceSet = sourceSets.create(mock) {
kotlin.srcDir("src/mock/kotlin")
compileClasspath += configurations[mock]
}
// include all the plugins as source paths, using the latest valid ktor release for each
for (pluginConfig in pluginConfigs.latestByPath().skipWebModules()) {
create(pluginConfig.name) {
kotlin.srcDir("plugins/${pluginConfig.path}")
compileClasspath += configurations[pluginConfig.name]
compileClasspath += mockSourceSet.output
pluginConfig.parent?.let { parent ->
compileClasspath += configurations[parent]
compileClasspath += sourceSets[parent].output
}
}
}
}
dependencies {
// mock configuration for referencing expected generated code
mock(kotlin("stdlib"))
mock("io.ktor:ktor-server-core:$latestKtor")
// create a build config for every plugin-release-module combination
for (pluginConfig in pluginConfigs.skipWebModules()) {
val release = pluginConfig.release
val config = pluginConfig.name
when(pluginConfig.module) {
ProjectModule.web -> {
config(kotlin("stdlib-wasm-js"))
}
ProjectModule.client -> {
config("io.ktor:ktor-client-mock:$release")
config("io.ktor:ktor-client-core:$release")
}
ProjectModule.server -> {
config(kotlin("stdlib-jdk8"))
config(kotlin("test-junit"))
config("io.ktor:ktor-server-core:$release")
config("io.ktor:ktor-server-test-host:$release")
}
else -> config(kotlin("stdlib"))
}
config(kotlin("test"))
// artifacts for the specific plugin version
for (artifact in pluginConfig.artifacts) {
when(artifact.function) {
null -> artifact.let { (group, name, version) ->
config("$group:$name:${version.resolvedString}")
}
"npm" -> {
config(npm(artifact.name, artifact.version.resolvedString))
}
}
}
}
// shared sources used in buildSrc
implementation(files("buildSrc/build/libs/shared.jar"))
// current ktor dependencies for handling manifests
implementation("io.ktor:ktor-server-core:$latestKtor")
implementation("io.ktor:ktor-client-core:$latestKtor")
implementation("io.ktor:ktor-client-cio:$latestKtor")
// inspection of install blocks
implementation(libs.kotlin.compiler)
// serialization
implementation(libs.kotlinx.serialization.json)
implementation(libs.kaml)
// resolving versions
implementation(libs.maven.artifact)
// logging
implementation(libs.logback.classic)
// finding changed files
implementation(libs.jgit)
implementation(libs.jgit.ssh.apache)
testImplementation(kotlin("test"))
}
detekt {
toolVersion = libs.versions.detekt.version.get()
config.setFrom(file("detekt.yml"))
buildUponDefaultConfig = true
}
tasks {
// use JUnit 5 for all test tasks
withType<Test> {
useJUnitPlatform()
}
// download all sources
compileKotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-Xcontext-receivers",
"-XdownloadSources=true"
)
}
}
// resolving plugin jars from custom classpaths
val resolvePlugins by registering {
group = "plugins"
description = "Locate plugin resources from version definitions"
doLast {
writeResolvedPluginConfigurations(pluginConfigs, logger) { configName ->
configurations[configName].resolvedConfiguration
}
}
}
// generates the appropriate directory structure with some templates for a new plugin
val createPlugin by registering(JavaExec::class) {
group = "plugins"
description = "Creates a skeleton for a new plugin"
mainClass = "io.ktor.plugins.registry.CreatePluginKt"
classpath = sourceSets["main"].runtimeClasspath
standardInput = System.`in`
}
// compiles ALL build targets before building the registry
val compileAll by registering {
group = "build"
description = "Compile all source sets"
dependsOn(withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>())
}
// builds the registry for distributing to the project generator
val buildRegistry by registering(JavaExec::class) {
group = "plugins"
description = "Build the registry from plugin resources"
mainClass = "io.ktor.plugins.registry.BuildRegistryKt"
classpath = sourceSets["main"].runtimeClasspath
dependsOn(resolvePlugins, compileAll)
}
// generates a test project using the modified plugins in the repository
val buildTestProject by registering(JavaExec::class) {
group = "plugins"
description = "Generates a test project from the newly registered plugins"
mainClass = "io.ktor.plugins.registry.GenerateTestProjectKt"
classpath = sourceSets["main"].runtimeClasspath
}
// compresses registry output into a tar file
val packageRegistry by registering(Tar::class) {
group = "plugins"
description = "Compresses registry to tar file for distribution"
archiveFileName.set("registry.tar.gz")
destinationDirectory.set(file("build/distributions"))
compression = Compression.GZIP
from("build/registry")
dependsOn(buildRegistry)
}
}