Skip to content

Commit

Permalink
Bump Kotlin to 2.1.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhuo committed Dec 15, 2024
1 parent b248a1b commit 22aff4e
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The Kace currently supports the above four most commonly used types. Other types
| 1.9.20-1.2.0 | 1.9.20 | 4.2.2 | 6.8.3 |
| 2.0.0-1.2.0 | 2.0.0 | 7.1.3 | 7.2 |
| 2.0.20-1.2.0 | 2.0.20 | 7.1.3 | 7.2 |
| 2.1.0-1.2.0 | 2.1.0 | 7.3.1 | 7.6.3 |

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

Expand Down
21 changes: 18 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "7.1.3" apply false
id("com.android.library") version "7.1.3" apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
id("com.android.application") version "7.3.1" apply false
id("com.android.library") version "7.3.1" apply false

// Use Kotlin 2.0.0 to build gradle plugin and compiler plugin for 2.1.0
// to avoid incompatible issue with gradle build.
id("org.jetbrains.kotlin.android") version "2.0.0" apply false
id("org.jetbrains.kotlin.jvm") version "2.0.0" apply false

id("com.vanniktech.maven.publish") version "0.18.0" apply false
id("com.github.gmazzo.buildconfig") version "2.1.0" apply false
}
Expand All @@ -19,4 +28,10 @@ allprojects {
pluginManager.withPlugin("java") {
extensions.getByType<JavaPluginExtension>().sourceCompatibility = JavaVersion.VERSION_1_8
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
extensions.getByType<KotlinJvmProjectExtension>().compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}
pluginManager.withPlugin("org.jetbrains.kotlin.android") {
extensions.getByType<KotlinAndroidProjectExtension>().compilerOptions.jvmTarget.set(JvmTarget.JVM_1_8)
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ kotlin.code.style=official
android.nonTransitiveRClass=true

KOTLIN_PLUGIN_ID=com.kanyun.kace
VERSION_NAME=2.0.20-1.2.0-SNAPSHOT
VERSION_NAME=2.1.0-1.2.0-SNAPSHOT

GROUP=com.kanyun.kace

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 29 08:11:34 CST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
14 changes: 8 additions & 6 deletions kace-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,20 @@ plugins {
`maven-publish`
}

// Build this project with Kotlin 2.0.0 for compatibility reason.
// But we should depend on libs for Kotlin 2.1.0.
val kotlinVersion = "2.1.0"

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect"))
implementation(kotlin("compiler-embeddable"))
implementation(kotlin("stdlib-jdk8", kotlinVersion))
implementation(kotlin("reflect", kotlinVersion))
implementation(kotlin("compiler-embeddable", kotlinVersion))

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

testImplementation(kotlin("test-junit"))
testImplementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")

testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.0.0-1.3.0")
testImplementation("com.bennyhuo.kotlin:kotlin-compile-testing-extensions:2.1.0-1.3.0")
}

val compileKotlin: KotlinCompile by tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ import org.jetbrains.kotlin.fir.symbols.SymbolInternals
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
import org.jetbrains.kotlin.fir.types.classId
import org.jetbrains.kotlin.fir.types.coneTypeSafe
import org.jetbrains.kotlin.fir.types.constructClassLikeType
import org.jetbrains.kotlin.fir.types.toSymbol
import org.jetbrains.kotlin.name.ClassId

/**
Expand All @@ -50,10 +48,10 @@ class KaceFirSupertypeGenerationExtension(
classLikeDeclaration: FirClassLikeDeclaration,
resolvedSupertypes: List<FirResolvedTypeRef>,
typeResolver: TypeResolveService,
): List<FirResolvedTypeRef> {
): List<ConeKotlinType> {
var shouldAddSuperType = false
OUTER@ for (superTypeRef in resolvedSupertypes) {
val superType = superTypeRef.type
val superType = superTypeRef.coneType
val classIds = listOf(superType.classId) + superType.allSuperTypeClassIds()
for (classId in classIds) {
if (classId == ANDROID_EXTENSIONS_CLASS_ID) {
Expand All @@ -69,12 +67,10 @@ class KaceFirSupertypeGenerationExtension(
if (!shouldAddSuperType) return emptyList()

return listOf(
buildResolvedTypeRef {
type = ANDROID_EXTENSIONS_CLASS_ID.constructClassLikeType(
emptyArray(),
isNullable = false,
)
},
ANDROID_EXTENSIONS_CLASS_ID.constructClassLikeType(
emptyArray(),
isMarkedNullable = false,
)
)
}

Expand Down
8 changes: 3 additions & 5 deletions kace-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ plugins {
}

dependencies {
implementation(kotlin("gradle-plugin"))
implementation(kotlin("stdlib-jdk8"))
compileOnly(kotlin("gradle-plugin"))
compileOnly(kotlin("stdlib-jdk8"))

compileOnly("com.android.tools.build:gradle:4.2.2")
compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0")
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable")
compileOnly("com.android.tools.build:gradle:7.3.1")
}

buildConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.kanyun.kace.gradle

import com.kanyun.kace.gradle.compat.ChangedFiles
import org.gradle.api.DefaultTask
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.DirectoryProperty
Expand All @@ -34,7 +35,6 @@ import org.gradle.work.ChangeType
import org.gradle.work.Incremental
import org.gradle.work.InputChanges
import org.gradle.workers.WorkerExecutor
import org.jetbrains.kotlin.incremental.ChangedFiles
import java.io.File
import javax.inject.Inject

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kanyun.kace.gradle.compat

import java.io.File
import java.io.Serializable

/**
* Copy this from Kotlin compiler to avoid depending on it explicitly.
*/
sealed class ChangedFiles : Serializable {
class Known(val modified: List<File>, val removed: List<File>, val forDependencies: Boolean = false) : ChangedFiles()
class Unknown : ChangedFiles()
companion object {
const val serialVersionUID: Long = 0
}
}
8 changes: 8 additions & 0 deletions kace-sample/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
Expand Down Expand Up @@ -96,4 +98,10 @@ kace {
else -> emptyMap()
}
}
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}
7 changes: 4 additions & 3 deletions kace-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") apply false
id("com.android.library") apply false
id("org.jetbrains.kotlin.android") version "2.0.20" apply false
id("com.android.application") version "7.3.1" apply false
id("com.android.library") version "7.3.1" apply false
id("org.jetbrains.kotlin.jvm") version "2.1.0" apply false
id("org.jetbrains.kotlin.android") version "2.1.0" apply false
id("com.kanyun.kace") version "0.0.0-SNAPSHOT" apply false
}

Expand Down
2 changes: 1 addition & 1 deletion kace-sample/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ kotlin_version = 1.7.0
kotlin_coroutine_version = 1.6.3

testAgp=false
agpVersion=7.1.3
agpVersion=7.3.1
2 changes: 1 addition & 1 deletion kace-sample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
8 changes: 8 additions & 0 deletions kace-sample/sample-lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
Expand Down Expand Up @@ -36,6 +38,12 @@ android {
resourcePrefix = "sample_lib"
}

kotlin {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
}
}

dependencies {
implementation("androidx.appcompat:appcompat:1.4.1")
}
16 changes: 8 additions & 8 deletions test_agp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ function testUnderAGPVersion() {

cd kace-sample

setGradleVersion 7.2
testUnderAGPVersion 7.1.3
setGradleVersion 7.6.3
testUnderAGPVersion 7.3.1

setGradleVersion 7.3.3
testUnderAGPVersion 7.2.0
setGradleVersion 7.6.3
testUnderAGPVersion 7.4.0

setGradleVersion 7.4
testUnderAGPVersion 7.3.0
setGradleVersion 8.0
testUnderAGPVersion 7.3.1

setGradleVersion 7.5
testUnderAGPVersion 7.4.0
setGradleVersion 8.5
testUnderAGPVersion 7.3.1

0 comments on commit 22aff4e

Please sign in to comment.