Skip to content

Commit

Permalink
KRPC-60 Update the project structure to use a new versioning (#92)
Browse files Browse the repository at this point in the history
* Update the project structure to use a new versioning

- Feature version for runtime modules
- Kotlin prefix version for compiler plugins

* Added language version parameters

* Moved KSP and Compiler plugins to standalone projects
  • Loading branch information
Mr3zee authored Jun 19, 2024
1 parent d371069 commit 430c5c6
Show file tree
Hide file tree
Showing 81 changed files with 452 additions and 381 deletions.
2 changes: 1 addition & 1 deletion bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
dependencies {
constraints {
rootProject.subprojects.filter {
it.plugins.hasPlugin("maven-publish") && it != project
it.name.startsWith(KOTLINX_RPC_PREFIX) && it != project
}.forEach { project ->
api(project)
}
Expand Down
19 changes: 6 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,27 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.serialization) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.rpc) apply false
alias(libs.plugins.kotlinx.rpc) apply false
alias(libs.plugins.atomicfu) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.kover.root.project) apply false
alias(libs.plugins.binary.compatibility.validator)
}

object Const {
const val COMPILER_PLUGIN_MODULE_NAME = "kotlinx-rpc-compiler-plugin"
const val INTERNAL_RPC_API_ANNOTATION = "kotlinx.rpc.internal.InternalRPCApi"
}

apiValidation {
ignoredPackages.add("kotlinx.rpc.internal")

val compilerPluginModules = subprojects.single { it.name == Const.COMPILER_PLUGIN_MODULE_NAME }.let {
it.subprojects.map { sub -> sub.name }
} + Const.COMPILER_PLUGIN_MODULE_NAME

ignoredProjects.addAll(
listOf(
"codegen-tests-jvm",
"codegen-tests-mpp",
"kotlinx-rpc-runtime-test",
"kotlinx-rpc-utils",
"kotlinx-rpc-utils-service-loader",
"kotlinx-rpc-ksp-plugin",
) + compilerPluginModules
)
)

nonPublicMarkers.add(Const.INTERNAL_RPC_API_ANNOTATION)
Expand All @@ -49,18 +42,18 @@ if (kotlinVersion >= "1.8.0") {

allprojects {
group = "org.jetbrains.kotlinx"
version = rootProject.libs.versions.rpc.full.get()
version = rootProject.libs.versions.kotlinx.rpc.get()
}

println("kotlinx.rpc project version: $version")
println("kotlinx.rpc project version: $version, Kotlin version: $kotlinVersion")

// If the prefix of the kPRC version is not Kotlin gradle plugin version - you have a problem :)
// Probably some dependency brings kotlin with higher version.
// To mitigate so, please refer to `gradle/kotlin-version-lookup.json`
// and it's usage in `gradle-settings-conventions/src/main/kotlin/settings-conventions.settings.gradle.kts`
val kotlinGPVersion = getKotlinPluginVersion()
if (!version.toString().startsWith(kotlinGPVersion)) {
error("KGP version mismatch. Project version: $version, KGP version: $kotlinGPVersion")
if (kotlinVersion != kotlinGPVersion) {
error("KGP version mismatch. Project version: $kotlinVersion, KGP version: $kotlinGPVersion")
}

// necessary for CI js tests
Expand Down
12 changes: 12 additions & 0 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import util.configureMetaTasks

val kotlinVersion: String by extra
val rpcVersion: String = libs.versions.kotlinx.rpc.get()

allprojects {
group = "org.jetbrains.kotlinx"
version = "$kotlinVersion-$rpcVersion"
}

plugins {
alias(libs.plugins.conventions.jvm)
Expand All @@ -17,3 +26,6 @@ subprojects {
}
}
}

configureMetaTasks("cleanTest", "test")
configureMetaTasks(tasks.matching { it.name.startsWith("publish") }.map { it.name })
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RPCCommandLineProcessor : CommandLineProcessor {

class RPCCompilerPlugin : ComponentRegistrar {
init {
VersionSpecificApi.upload(VersionSpecificApiImpl)
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
}

override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RPCCommandLineProcessor : CommandLineProcessor {

class RPCCompilerPlugin : ComponentRegistrar {
init {
VersionSpecificApi.upload(VersionSpecificApiImpl)
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
}

override val supportsK2: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RPCCommandLineProcessor : CommandLineProcessor {
@OptIn(ExperimentalCompilerApi::class)
class RPCCompilerPlugin : CompilerPluginRegistrar() {
init {
VersionSpecificApi.upload(VersionSpecificApiImpl)
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
}

override val supportsK2: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RPCCommandLineProcessor : CommandLineProcessor {
@OptIn(ExperimentalCompilerApi::class)
class RPCCompilerPlugin : CompilerPluginRegistrar() {
init {
VersionSpecificApi.upload(VersionSpecificApiImpl)
VersionSpecificApi.INSTANCE = VersionSpecificApiImpl
}

override val supportsK2: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
object RPCCompilerPluginCore {
fun provideExtension(configuration: CompilerConfiguration): IrGenerationExtension {
val logger = configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)
val versionSpecificApi = VersionSpecificApi.loadService()
val versionSpecificApi = VersionSpecificApi.INSTANCE

return RPCIrExtension(logger, versionSpecificApi)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package kotlinx.rpc.codegen

import kotlinx.rpc.internal.service.CompanionServiceContainer
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.platform.TargetPlatform
Expand All @@ -14,5 +13,7 @@ interface VersionSpecificApi {

fun referenceClass(context: IrPluginContext, packageName: String, name: String): IrClassSymbol?

companion object : CompanionServiceContainer<VersionSpecificApi>(VersionSpecificApi::class)
companion object {
lateinit var INSTANCE: VersionSpecificApi
}
}
15 changes: 15 additions & 0 deletions compiler-plugin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

rootProject.name = "kotlinx-rpc-compiler-plugin"

pluginManagement {
includeBuild("../gradle-conventions")
includeBuild("../gradle-settings-conventions")
}

plugins {
id("settings-conventions")
id("compiler-specific-modules")
}
19 changes: 6 additions & 13 deletions gradle-conventions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,32 @@ configurations.configureEach {
val kotlinVersion: String by extra

dependencies {
implementation(libs.kotlin.gradle.plugin)
implementation(libs.detekt.gradle.plugin)

if (kotlinVersion >= "1.8.0") {
implementation(libs.kover.gradle.plugin)
}

// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(project(":kotlin-version"))
implementation(project(":conventions-utils"))
}

gradlePlugin {
plugins {
named("conventions-publishing") {
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}

plugins {
named("conventions-common") {
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}

plugins {
named("conventions-jvm") {
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}

plugins {
named("conventions-kmp") {
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
gradlePlugin {
plugins {
named("compiler-specific-module") {
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ fun capitalize(string: String): String {
object CSM {
const val KOTLIN_MULTIPLATFORM_PLUGIN_ID = "org.jetbrains.kotlin.multiplatform"
const val KOTLIN_JVM_PLUGIN_ID = "org.jetbrains.kotlin.jvm"

const val SERVICE_LOADER_MODULE = ":kotlinx-rpc-utils:kotlinx-rpc-utils-service-loader"
}

val kotlinVersion = getKotlinPluginVersion()
Expand Down Expand Up @@ -50,18 +48,15 @@ fun Project.lazyApi(notation: Any) {
lazyDependency("api", notation)
}

fun Project.lazyImplementation(notation: Any) {
lazyDependency("implementation", notation)
}


val root = project

subprojects {
afterEvaluate {
println("Compiler-specific module $name, version: $version")
}

when {
name == coreProjectName -> {
lazyImplementation(project(CSM.SERVICE_LOADER_MODULE))

root.lazyApi(this)
}

Expand All @@ -74,8 +69,6 @@ subprojects {
if (kotlinVersion.startsWith(semVer)) {
val coreProject = root.subprojects.singleOrNull { it.name == coreProjectName }
?: error("Expected to find subproject with name '$coreProjectName'")

lazyImplementation(project(CSM.SERVICE_LOADER_MODULE))
lazyApi(coreProject)

root.lazyApi(this)
Expand Down
30 changes: 30 additions & 0 deletions gradle-conventions/conventions-utils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
alias(libs.plugins.gradle.kotlin.dsl)
}

configurations.configureEach {
resolutionStrategy {
force(libs.kotlin.reflect)
force(libs.kotlin.stdlib)
force(libs.kotlin.stdlib.jdk7)
force(libs.kotlin.stdlib.jdk8)
}
}

val kotlinVersion: String by extra

dependencies {
api(libs.kotlin.gradle.plugin)
api(libs.detekt.gradle.plugin)

if (kotlinVersion >= "1.8.0") {
api(libs.kover.gradle.plugin)
}

// https://stackoverflow.com/questions/76713758/use-version-catalog-inside-precompiled-gradle-plugin
api(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

package util

import org.gradle.api.*
import org.gradle.kotlin.dsl.*
import java.io.*
import org.gradle.api.Project
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.gradle.kotlin.dsl.invoke
import java.io.File

internal fun Project.configureJs() {
fun Project.configureJs() {
configureJsTasks()

kotlin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

internal fun Project.kotlin(block: KotlinMultiplatformExtension.() -> Unit) {
fun Project.kotlin(block: KotlinMultiplatformExtension.() -> Unit) {
configure(block)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package util

import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

internal fun KotlinProjectExtension.optInForRPCApi() {
fun KotlinProjectExtension.optInForRPCApi() {
sourceSets.all {
languageSettings.optIn("kotlinx.rpc.internal.InternalRPCApi")
languageSettings.optIn("kotlinx.rpc.internal.ExperimentalRPCApi")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package util

import org.gradle.api.Project

fun Project.configureMetaTasks(vararg taskNames: String) {
configureMetaTasks(taskNames.toList())
}

fun Project.configureMetaTasks(taskNames: List<String>) {
val root = this
val metaSet = taskNames.toSet()

subprojects.forEach {
it.tasks.all {
val subtask = this

if (subtask.name in metaSet) {
val metaTask = root.tasks.findByName(subtask.name)
?: root.task(subtask.name)

metaTask.dependsOn(subtask)

metaTask.group = "meta"
}
}
}
}
2 changes: 1 addition & 1 deletion gradle-conventions/gradle-publish-stub/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gradlePlugin {
plugins {
named("conventions-gradle-publish") {
id = "conventions-gradle-publish"
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}
}
2 changes: 1 addition & 1 deletion gradle-conventions/gradle-publish/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ gradlePlugin {
plugins {
named("conventions-gradle-publish") {
id = "conventions-gradle-publish"
version = libs.versions.rpc.core.get()
version = libs.versions.kotlinx.rpc.get()
}
}
}
Loading

0 comments on commit 430c5c6

Please sign in to comment.