Skip to content

Commit 15e07b7

Browse files
committed
Move all gradle plugin code to one module (#123)
1 parent 3090f07 commit 15e07b7

File tree

10 files changed

+76
-132
lines changed

10 files changed

+76
-132
lines changed

gradle-plugin/build.gradle.kts

Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,91 @@
33
*/
44

55
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
6-
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
7-
import util.configureMetaTasks
86

97
plugins {
10-
alias(libs.plugins.conventions.jvm) apply false
11-
alias(libs.plugins.conventions.gradle.publish) apply false
12-
alias(libs.plugins.gradle.kotlin.dsl) apply false
13-
alias(libs.plugins.gradle.plugin.publish) apply false
8+
alias(libs.plugins.conventions.jvm)
9+
alias(libs.plugins.conventions.gradle.publish)
10+
alias(libs.plugins.gradle.kotlin.dsl)
11+
alias(libs.plugins.gradle.plugin.publish)
1412
}
1513

16-
subprojects {
17-
group = "org.jetbrains.kotlinx"
18-
version = rootProject.libs.versions.kotlinx.rpc.get()
14+
group = "org.jetbrains.kotlinx"
15+
version = rootProject.libs.versions.kotlinx.rpc.get()
1916

20-
fun alias(notation: Provider<PluginDependency>): String {
21-
return notation.get().pluginId
17+
kotlin {
18+
explicitApi = ExplicitApiMode.Disabled
19+
}
20+
21+
dependencies {
22+
compileOnly(libs.kotlin.gradle.plugin)
23+
}
24+
25+
// This block is needed to show plugin tasks on --dry-run
26+
// and to not run task actions on ":plugin:task --dry-run".
27+
// The bug is known since June 2017 and still not fixed.
28+
// The workaround used below is described here: https://github.com/gradle/gradle/issues/2517#issuecomment-437490287
29+
if (gradle.parent != null && gradle.parent!!.startParameter.isDryRun) {
30+
gradle.startParameter.isDryRun = true
31+
}
32+
33+
gradlePlugin {
34+
plugins {
35+
create("plugin") {
36+
id = "org.jetbrains.kotlinx.rpc.plugin"
37+
38+
displayName = "kotlinx.rpc Gradle Plugin"
39+
implementationClass = "kotlinx.rpc.RPCGradlePlugin"
40+
description = """
41+
The plugin ensures correct RPC configurations for your project, that will allow proper code generation.
42+
43+
Additionally, it enforces proper artifacts versions for your project, depending on your Kotlin version.
44+
Resulting versions of the kotlinx.rpc dependencies will be 'kotlinVersion-kotlinxRpcVersion', for example '1.9.24-0.2.0', where '0.2.0' is the kotlinx.rpc version.
45+
""".trimIndent()
46+
}
2247
}
2348

24-
afterEvaluate {
25-
plugins.apply(alias(rootProject.libs.plugins.conventions.jvm))
49+
plugins {
50+
create("platform") {
51+
id = "org.jetbrains.kotlinx.rpc.platform"
2652

27-
configure<KotlinJvmProjectExtension> {
28-
explicitApi = ExplicitApiMode.Disabled
53+
displayName = "kotlinx.rpc Platform Plugin"
54+
implementationClass = "kotlinx.rpc.RPCPlatformPlugin"
55+
description = """
56+
The plugin enforces proper artifacts versions for your project, depending on your Kotlin version.
57+
Resulting versions of the kotlinx.rpc dependencies will be 'kotlinVersion-kotlinxRpcVersion', for example '1.9.24-0.2.0', where '0.2.0' is the kotlinx.rpc version.
58+
""".trimIndent()
2959
}
3060
}
31-
plugins.apply(alias(rootProject.libs.plugins.gradle.kotlin.dsl))
32-
plugins.apply(alias(rootProject.libs.plugins.conventions.gradle.publish))
33-
34-
// This block is needed to show plugin tasks on --dry-run
35-
// and to not run task actions on ":plugin:task --dry-run".
36-
// The bug is known since June 2017 and still not fixed.
37-
// The workaround used below is described here: https://github.com/gradle/gradle/issues/2517#issuecomment-437490287
38-
if (gradle.parent != null && gradle.parent!!.startParameter.isDryRun) {
39-
gradle.startParameter.isDryRun = true
61+
}
62+
63+
abstract class GeneratePluginVersionTask @Inject constructor(
64+
@get:Input val pluginVersion: String,
65+
@get:OutputDirectory val sourcesDir: File
66+
) : DefaultTask() {
67+
@TaskAction
68+
fun generate() {
69+
val sourceFile = File(sourcesDir, "PluginVersion.kt")
70+
71+
sourceFile.writeText(
72+
"""
73+
package kotlinx.rpc
74+
75+
const val PLUGIN_VERSION = "$pluginVersion"
76+
77+
""".trimIndent()
78+
)
4079
}
4180
}
4281

43-
configureMetaTasks(
44-
"publishAllPublicationsToBuildRepoRepository", // publish to locally (to the build/repo folder)
45-
"publishAllPublicationsToSpaceRepository", // publish to Space
46-
"publishPlugins", // publish to Gradle Plugin Portal
47-
"publishToMavenLocal", // for local plugin development
48-
"validatePlugins", // plugin validation
49-
excludeSubprojects = listOf("gradle-plugin-api"),
50-
)
51-
52-
configureMetaTasks(
53-
"detekt", // run Detekt tasks
54-
"clean",
55-
)
82+
val sourcesDir = File(project.layout.buildDirectory.asFile.get(), "generated-sources/pluginVersion")
83+
84+
val generatePluginVersionTask =
85+
tasks.register<GeneratePluginVersionTask>("generatePluginVersion", version.toString(), sourcesDir)
86+
87+
kotlin {
88+
sourceSets {
89+
main {
90+
kotlin.srcDir(generatePluginVersionTask.map { it.sourcesDir })
91+
}
92+
}
93+
}

gradle-plugin/gradle-plugin-all/build.gradle.kts

Lines changed: 0 additions & 29 deletions
This file was deleted.

gradle-plugin/gradle-plugin-api/build.gradle.kts

Lines changed: 0 additions & 39 deletions
This file was deleted.

gradle-plugin/gradle-plugin-platform/build.gradle.kts

Lines changed: 0 additions & 24 deletions
This file was deleted.

gradle-plugin/settings.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ plugins {
1515
id("settings-conventions")
1616
}
1717

18-
includePublic(":gradle-plugin-api")
19-
includePublic(":gradle-plugin-all")
20-
includePublic(":gradle-plugin-platform")
18+
includeRootAsPublic()

0 commit comments

Comments
 (0)