forked from ktorio/ktor-plugin-registry
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
168 lines (142 loc) · 5.13 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
/*
* 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"
configurations {
for (target in targets)
target.releaseConfigs.forEach(::create)
}
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")
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)
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 for all test tasks
withType<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.
*/
val copyPluginTypes by registering(Copy::class) {
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 {
compilerOptions {
freeCompilerArgs.addAll(
"-Xcontext-receivers",
"-XdownloadSources=true"
)
}
dependsOn(copyPluginTypes)
}
// resolving plugin jars from custom classpaths
val resolvePlugins by registering {
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
)
}
}
}
// 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`
}
// 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)
}
// 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)
}
}