|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode |
6 | | -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension |
7 | | -import util.configureMetaTasks |
8 | 6 |
|
9 | 7 | 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) |
14 | 12 | } |
15 | 13 |
|
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() |
19 | 16 |
|
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 | + } |
22 | 47 | } |
23 | 48 |
|
24 | | - afterEvaluate { |
25 | | - plugins.apply(alias(rootProject.libs.plugins.conventions.jvm)) |
| 49 | + plugins { |
| 50 | + create("platform") { |
| 51 | + id = "org.jetbrains.kotlinx.rpc.platform" |
26 | 52 |
|
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() |
29 | 59 | } |
30 | 60 | } |
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 | + ) |
40 | 79 | } |
41 | 80 | } |
42 | 81 |
|
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 | +} |
0 commit comments