Skip to content

Commit e67c566

Browse files
authored
Support Kotlin 2.2.0 (#79)
* ADD: support kotlin 2.2.0 * MOD: Migrating from kts to gradle to avoid Kotlin version issues
1 parent 4a3dbfb commit e67c566

File tree

22 files changed

+384
-426
lines changed

22 files changed

+384
-426
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: ./gradlew publishToMavenLocal -PVERSION_NAME=0.0.0-SNAPSHOT
4242

4343
- name: Check spotless
44-
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache
44+
run: ./gradlew spotlessCheck --init-script gradle/init.gradle --no-configuration-cache
4545

4646
- name: Test AGP compatibility
4747
run: chmod +x ./test_agp.sh && ./test_agp.sh

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ The Kace currently supports the above four most commonly used types. Other types
7777
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
7878
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |
7979
| 2.0.20-1.2.0 | 2.0.20 | 7.1.3 | 7.2 |
80-
| 2.1.0-1.2.0 | 2.1.0 | 7.3.1 | 7.6.3 |
80+
| 2.1.0-1.2.0 | 2.1.0 | 7.3.1 | 7.6.3 |
81+
| 2.2.0-1.2.0 | 2.2.0 | 7.3.1 | 7.6.3 |
8182

8283
Since the goal of the Kace is to help developers easily upgrade to Kotlin 1.8, the minimum supported version of Kotlin is relatively high
8384

build.gradle

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
plugins {
3+
id 'com.android.application' version '7.3.1' apply false
4+
id 'com.android.library' version '7.3.1' apply false
5+
6+
// Use Kotlin 2.0.0 to build gradle plugin and compiler plugin for 2.1.0
7+
// to avoid incompatible issue with gradle build.
8+
id 'org.jetbrains.kotlin.android' version '2.2.0' apply false
9+
id 'org.jetbrains.kotlin.jvm' version '2.2.0' apply false
10+
11+
id 'com.vanniktech.maven.publish' version '0.18.0' apply false
12+
id 'com.github.gmazzo.buildconfig' version '2.1.0' apply false
13+
}
14+
15+
allprojects {
16+
repositories {
17+
mavenCentral()
18+
google()
19+
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
20+
}
21+
22+
apply plugin: "com.vanniktech.maven.publish"
23+
24+
plugins.withId("java") {
25+
project.extensions.getByType(org.gradle.api.plugins.JavaPluginExtension).sourceCompatibility = org.gradle.api.JavaVersion.VERSION_1_8
26+
}
27+
plugins.withId("org.jetbrains.kotlin.jvm") {
28+
project.extensions.getByType(org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension).compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
29+
}
30+
plugins.withId("org.jetbrains.kotlin.android") {
31+
project.extensions.getByType(org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension).compilerOptions.jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
32+
}
33+
}

build.gradle.kts

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

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ kotlin.code.style=official
2323
android.nonTransitiveRClass=true
2424

2525
KOTLIN_PLUGIN_ID=com.kanyun.kace
26-
VERSION_NAME=2.1.0-1.2.0
26+
VERSION_NAME=2.2.0-1.2.0-SNAPSHOT
2727

2828
GROUP=com.kanyun.kace
2929

gradle/init.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
ext.ktlintVersion = "0.49.1"
2+
3+
initscript {
4+
def spotlessVersion = "6.19.0"
5+
6+
repositories {
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion"
12+
}
13+
}
14+
15+
rootProject {
16+
subprojects {
17+
apply plugin: com.diffplug.gradle.spotless.SpotlessPlugin
18+
spotless {
19+
kotlin {
20+
target '**/*.kt'
21+
targetExclude '**/build/**/*.kt'
22+
ktlint(ktlintVersion).userData(
23+
[
24+
"android" : "true",
25+
"max_line_length" : "200",
26+
"ij_kotlin_allow_trailing_comma" : "false",
27+
"ij_kotlin_allow_trailing_comma_on_call_site": "false"
28+
]
29+
)
30+
licenseHeaderFile rootProject.file("spotless/copyright.kt")
31+
}
32+
format 'kts', {
33+
target '**/*.kts'
34+
targetExclude '**/build/**/*.kts'
35+
// Look for the first line that doesn't have a block comment (assumed to be the license)
36+
licenseHeaderFile rootProject.file("spotless/copyright.kts"), "(^(?![\\\\/ ]\\\\*).*\$)"
37+
}
38+
format 'xml', {
39+
target '**/*.xml'
40+
targetExclude '**/build/**/*.xml'
41+
// Look for the first XML tag that isn't a comment (<!--) or the xml declaration (<?xml)
42+
licenseHeaderFile rootProject.file("spotless/copyright.xml"), "(<[^!?])"
43+
}
44+
}
45+
}
46+
}

gradle/init.gradle.kts

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

kace-compiler/build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2022 KanYun
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id 'org.jetbrains.kotlin.jvm'
19+
id 'java'
20+
id 'org.jetbrains.kotlin.kapt'
21+
id 'com.github.gmazzo.buildconfig'
22+
id 'com.vanniktech.maven.publish'
23+
id 'maven-publish'
24+
}
25+
26+
// Build this project with Kotlin 2.0.0 for compatibility reason.
27+
// But we should depend on libs for Kotlin 2.1.0.
28+
def kotlinVersion = "2.2.0"
29+
30+
dependencies {
31+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}"
32+
implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}"
33+
implementation "org.jetbrains.kotlin:kotlin-compiler-embeddable:${kotlinVersion}"
34+
35+
kapt "com.google.auto.service:auto-service:1.0.1"
36+
compileOnly "com.google.auto.service:auto-service-annotations:1.0.1"
37+
38+
testImplementation "org.jetbrains.kotlin:kotlin-test-junit"
39+
testImplementation "com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.2.0-1.3.0"
40+
}
41+
42+
tasks.named('compileKotlin', org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
43+
compilerOptions {
44+
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
45+
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
46+
}
47+
}
48+
49+
buildConfig {
50+
packageName = project.group
51+
buildConfigField "String", "KOTLIN_PLUGIN_ID", "\"${project.property('KOTLIN_PLUGIN_ID')}\""
52+
}

kace-compiler/build.gradle.kts

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

kace-compiler/src/main/java/com/kanyun/kace/compiler/KaceIrTransformer.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import org.jetbrains.kotlin.ir.types.defaultType
4545
import org.jetbrains.kotlin.ir.types.makeNullable
4646
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
4747
import org.jetbrains.kotlin.ir.util.constructors
48+
import org.jetbrains.kotlin.ir.util.nonDispatchParameters
4849
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
4950

5051
class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransformerVoid() {
@@ -99,11 +100,9 @@ class KaceIrTransformer(private val context: IrPluginContext) : IrElementTransfo
99100
).apply {
100101
dispatchReceiver = androidExtensionsValue
101102

102-
valueParameters.forEachIndexed { index, irValueParameter ->
103-
putValueArgument(
104-
index,
105-
irGet(irValueParameter.type, irValueParameter.symbol),
106-
)
103+
nonDispatchParameters.forEachIndexed { index, irValueParameter ->
104+
arguments[index + 1] =
105+
irGet(irValueParameter.type, irValueParameter.symbol)
107106
}
108107
},
109108
)

0 commit comments

Comments
 (0)