forked from ktorio/ktor-plugin-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
157 lines (131 loc) · 4.33 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
/*
* 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.*
import java.nio.file.Paths
val targets by lazy { fetchKtorTargets(logger) }
plugins {
alias(libs.plugins.serialization)
alias(libs.plugins.jvm)
alias(libs.plugins.detekt)
}
group = "io.ktor"
version = "1.0-SNAPSHOT"
repositories {
allRepositories()
}
configurations {
for (target in targets)
target.releaseConfigs.forEach(::create)
}
kotlin {
jvmToolchain {
check(this is JavaToolchainSpec)
languageVersion.set(JavaLanguageVersion.of(11))
}
}
dependencies {
// each ktor version has its own classpath
for (target in targets) {
for ((config, version) in target.releases) {
config("io.ktor:ktor-${target.name}-core:$version")
config(kotlin("stdlib"))
// test imports for test_function template
if (target.name == "server") {
config(kotlin("test"))
config(kotlin("test-junit"))
config("io.ktor:ktor-server-test-host:$version")
}
for (dependency in target.allArtifactsForVersion(version))
config(dependency)
}
}
val latestKtor = targets.first().releases.last().version
// current ktor dependencies for handling manifests
implementation("io.ktor:ktor-server-core:$latestKtor")
implementation("io.ktor:ktor-client-core:$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.kotlin.logging)
implementation(libs.slf4j.simple)
testImplementation(kotlin("test"))
}
// include relevant copied classes from buildSrc module
sourceSets {
main {
kotlin {
srcDir("build/copied")
}
}
}
detekt {
toolVersion = libs.versions.detekt.version.get()
config.setFrom(file("detekt.yml"))
buildUponDefaultConfig = true
}
tasks {
// use junit 5
test {
useJUnitPlatform()
}
/**
* We copy this shared source file with the parent project because there is otherwise
* a chicken/egg problem with building the project which confuses the IDEA.
*/
register<Copy>("copyPluginTypes") {
group = "build"
from(
"buildSrc/src/main/kotlin/io/ktor/plugins/registry/PluginReference.kt",
"buildSrc/src/main/kotlin/io/ktor/plugins/registry/PluginCollector.kt",
)
into("build/copied")
}
// download all sources
compileKotlin {
kotlinOptions {
freeCompilerArgs = listOf("-XdownloadSources=true")
}
dependsOn("copyPluginTypes")
}
// resolving plugin jars from custom classpaths
register("resolvePlugins") {
group = "plugins"
description = "Locate plugin resources from version definitions"
doLast {
for (target in targets) {
val resolvedArtifacts = target.releases.associate { release ->
release.version to configurations[release.config].resolvedConfiguration.resolvedArtifacts
}
outputReleaseArtifacts(
outputFile = Paths.get("build/${target.name}-artifacts.yaml"),
configurations = resolvedArtifacts
)
}
}
}
// builds the registry for distributing to the project generator
register<JavaExec>("buildRegistry") {
group = "plugins"
description = "Build the registry from plugin resources"
mainClass = "io.ktor.plugins.registry.BuildRegistryKt"
classpath = sourceSets["main"].runtimeClasspath
dependsOn("resolvePlugins")
}
// compresses registry output into a tar file
register<Tar>("packageRegistry") {
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")
}
}