Skip to content

Commit

Permalink
Use VersionCatalog manage version and bump Kotlin to 1.8.22 with init…
Browse files Browse the repository at this point in the history
…ial support for k2 compiler frontend
  • Loading branch information
guodongAndroid committed Nov 23, 2023
1 parent fb1ea30 commit 3628ffb
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 76 deletions.
2 changes: 1 addition & 1 deletion api-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
alias(libs.plugins.kotlin.jvm)
}

java {
Expand Down
24 changes: 9 additions & 15 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
// id("com.guodong.android.sword.kcp")
id("com.sunxiaodou.kotlin.sword.kcp")
id("com.google.devtools.ksp")
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.sword)
alias(libs.plugins.google.ksp)
}

android {
Expand Down Expand Up @@ -66,18 +65,13 @@ ksp {

dependencies {

implementation("androidx.core:core-ktx:1.7.0")
implementation("androidx.appcompat:appcompat:1.4.1")
implementation("com.google.android.material:material:1.6.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.google.android.material)

debugImplementation(project(":api-kotlin"))
releaseImplementation("com.sunxiaodou.kotlin:sword-api-kt:${project.extra["PLUGIN_VERSION"]}")
releaseImplementation(libs.sword.api.kotlin)

kspDebug(project(":compiler:ksp"))
kspRelease("com.sunxiaodou.kotlin:sword-compiler-ksp:${project.extra["PLUGIN_VERSION"]}")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
kspRelease(libs.sword.compiler.ksp)
}
17 changes: 10 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
/*buildscript {
repositories {
google()
mavenCentral()
Expand All @@ -20,14 +20,17 @@ buildscript {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
}*/

plugins {
kotlin("jvm") version "1.7.10" apply false
id("com.google.devtools.ksp") version "1.7.10-1.0.6" apply false
id("com.github.gmazzo.buildconfig") version "3.1.0" apply false
id("com.vanniktech.maven.publish") version "0.22.0" apply false
id("com.sunxiaodou.kotlin.sword.kcp") version "0.0.2" apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.kapt) apply false
alias(libs.plugins.google.ksp) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.build.config) apply false
alias(libs.plugins.maven.publish) apply false
alias(libs.plugins.sword) apply false
}

allprojects {
Expand Down
12 changes: 6 additions & 6 deletions compiler/ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
alias(libs.plugins.kotlin.jvm)
}

java {
Expand All @@ -10,15 +10,15 @@ java {
}

dependencies {
implementation("com.google.devtools.ksp:symbol-processing-api:1.7.10-1.0.6")
implementation("com.squareup:kotlinpoet:1.14.2")
implementation("com.squareup:kotlinpoet-ksp:1.12.0")
implementation(libs.google.ksp.api)
implementation(libs.kotlin.poet)
implementation(libs.kotlin.poet.ksp)
implementation(project(":api-kotlin"))

testImplementation(project(":api-kotlin"))
testImplementation(kotlin("test-junit"))
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
testImplementation("com.github.tschuchortdev:kotlin-compile-testing-ksp:1.4.9")
testImplementation(libs.kotlin.compile.testing)
testImplementation(libs.kotlin.compile.testing.ksp)
}

tasks.withType<KotlinCompile> {
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ kotlin.code.style=official
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=false

PLUGIN_VERSION=0.0.2
KOTLIN_PLUGIN_ID=com.sunxiaodou.kotlin.sword.kcp

GROUP=com.sunxiaodou.kotlin

# PLUGIN_VERSION
VERSION_NAME=0.0.2
VERSION_NAME=0.0.3-SNAPSHOT

POM_NAME=Sword
POM_DESCRIPTION=Implemented using kotlin compiler plugin, currently only applicable to Kotlin functions, providing proxy implementation for Kotlin functions.
Expand Down
55 changes: 55 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[versions]
android-gradle-plugin = "7.4.2"
androidx-core = "1.7.0"
androidx-appcompat = "1.4.1"

google-android-material = "1.6.0"
google-auto-service = "1.0.1"
google-ksp = "1.8.22-1.0.11"

build-config = "3.0.3"
maven-publish = "0.22.0"
kotlin = "1.8.22"
kotlin-android-plugin = "1.8.22"
kotlin-poet = "1.14.2"
koltin-poet-ksp = "1.12.0"
kotlin-compile-test = "1.5.0"

plugin = "0.0.3-SNAPSHOT"

[libraries]
android-gradle-plugin = { module = "com.android.tools.build:gradle", version.ref = "android-gradle-plugin" }

androidx-core-ktx = { module = "androidx.core:core-ktx", version.ref = "androidx-core" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }

google-android-material = { module = "com.google.android.material:material", version.ref = "google-android-material" }
google-auto-service = { module = "com.google.auto.service:auto-service", version.ref = "google-auto-service" }
google-auto-service-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "google-auto-service" }
google-ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "google-ksp" }

kotlin-compiler-embeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
kotlin-poet = { module = "com.squareup:kotlinpoet", version.ref = "kotlin-poet" }
kotlin-poet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "koltin-poet-ksp" }
kotlin-test-junit = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = "kotlin" }
kotlin-compile-testing = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlin-compile-test" }
kotlin-compile-testing-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref = "kotlin-compile-test" }

sword-api-kotlin = { group = "com.sunxiaodou.kotlin", name = "sword-api-kt", version.ref = "plugin" }
sword-compiler-ksp = { group = "com.sunxiaodou.kotlin", name = "sword-compiler-ksp", version.ref = "plugin" }

[plugins]
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin-android-plugin" }
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }

google-ksp = { id = "com.google.devtools.ksp", version.ref = "google-ksp" }

android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }
build-config = { id = "com.github.gmazzo.buildconfig", version.ref = "build-config" }
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "maven-publish" }

sword = { id = "com.sunxiaodou.kotlin.sword.kcp", version.ref = "plugin" }

[bundles]

8 changes: 4 additions & 4 deletions kcp/plugin-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("java-gradle-plugin")
kotlin("jvm")
id("com.github.gmazzo.buildconfig")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.build.config)
}

java {
Expand All @@ -18,9 +18,9 @@ dependencies {
buildConfig {
packageName("com.guodong.android.sword.kcp.gradle")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["KOTLIN_PLUGIN_ID"]}\"")
buildConfigField("String", "KOTLIN_PLUGIN_GROUP", "\"com.guodong.android\"")
buildConfigField("String", "KOTLIN_PLUGIN_GROUP", "\"com.sunxiaodou.kotlin\"")
buildConfigField("String", "KOTLIN_PLUGIN_NAME", "\"sword-kcp-kotlin-plugin\"")
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${rootProject.extra["PLUGIN_VERSION"]}\"")
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${rootProject.extra["VERSION_NAME"]}\"")
}

gradlePlugin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.SubpluginOption
class SwordGradlePlugin : KotlinCompilerPluginSupportPlugin {

override fun apply(target: Project) = with(target) {
logger.error("Welcome to guodongAndroid sword kcp gradle plugin.")
logger.error("Welcome to guodongAndroid sword kcp gradle plugin (${BuildConfig.KOTLIN_PLUGIN_VERSION}).")
}

override fun isApplicable(kotlinCompilation: KotlinCompilation<*>): Boolean = true
Expand Down
33 changes: 15 additions & 18 deletions kcp/plugin-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
kotlin("kapt")
id("com.github.gmazzo.buildconfig")
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.kapt)
alias(libs.plugins.build.config)
}

java {
Expand All @@ -12,32 +12,29 @@ java {
}

dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-compiler-embeddable")
compileOnly(libs.kotlin.compiler.embeddable)

kapt("com.google.auto.service:auto-service:1.0.1")
compileOnly("com.google.auto.service:auto-service-annotations:1.0.1")
kapt(libs.google.auto.service)
compileOnly(libs.google.auto.service.annotations)

testImplementation(project(":api-kotlin"))
testImplementation(kotlin("test-junit"))
testImplementation("com.github.tschuchortdev:kotlin-compile-testing:1.4.9")
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.kotlin.compile.testing)
}

buildConfig {
packageName("com.guodong.android.sword.kcp.kotlin")
buildConfigField("String", "KOTLIN_PLUGIN_ID", "\"${rootProject.extra["KOTLIN_PLUGIN_ID"]}\"")
buildConfigField("String", "KOTLIN_PLUGIN_VERSION", "\"${rootProject.extra["VERSION_NAME"]}\"")
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

tasks.register("sourcesJar", Jar::class) {
group = "build"
description = "Assembles Kotlin sources"

archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
dependsOn(tasks.classes)
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs += listOf(
"-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi",
)
}
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,30 @@ import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.codegen.extensions.ClassBuilderInterceptorExtension
import org.jetbrains.kotlin.com.intellij.mock.MockProject
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
import org.jetbrains.kotlin.config.CompilerConfiguration

/**
* Created by guodongAndroid on 2022/08/15.
*/
@AutoService(ComponentRegistrar::class)
class SwordComponentRegistrar : ComponentRegistrar {
@AutoService(CompilerPluginRegistrar::class)
class SwordCompilerPluginRegistrar : CompilerPluginRegistrar() {

override fun registerProjectComponents(
project: MockProject,
configuration: CompilerConfiguration
) {
override val supportsK2: Boolean = true

override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
val messageCollector =
configuration.get(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, MessageCollector.NONE)

messageCollector.report(
CompilerMessageSeverity.WARNING,
"Welcome to guodongAndroid sword kcp kotlin plugin"
"Welcome to guodongAndroid sword kcp kotlin plugin (${BuildConfig.KOTLIN_PLUGIN_VERSION})."
)

/*ClassBuilderInterceptorExtension.registerExtension(
project,
SwordClassGenerationInterceptor(messageCollector)
)*/

IrGenerationExtension.registerExtension(
project,
SwordIrGenerationExtension(messageCollector)
)
IrGenerationExtension.registerExtension(SwordIrGenerationExtension(messageCollector))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName

class SwordIrGenerationExtension(
Expand All @@ -20,7 +21,7 @@ class SwordIrGenerationExtension(
)

val proxyAnnotation =
pluginContext.referenceClass(proxyAnnotationFqName)
pluginContext.referenceClass(ClassId.topLevel(proxyAnnotationFqName))
if (proxyAnnotation == null) {
messageCollector.report(
CompilerMessageSeverity.ERROR,
Expand Down
Loading

0 comments on commit 3628ffb

Please sign in to comment.