Skip to content

Commit

Permalink
Update Kotlin to 2.0.21
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelWilcox committed Oct 30, 2024
1 parent 1569988 commit 78775e0
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 52 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
Expand All @@ -36,7 +36,7 @@ jobs:
strategy:
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
Expand Down Expand Up @@ -162,8 +162,8 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
agp-version: [ 7.1.1, 7.2.0, 7.3.1 ]
kotlin-version: [ 2.0.21 ]
agp-version: [ 7.2.0, 7.3.1 ]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
# solution.
fail-fast: false
matrix:
kotlin-version: [ 1.9.24 ]
kotlin-version: [ 2.0.21 ]

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
Expand Down
2 changes: 1 addition & 1 deletion annotations-optional/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
javax.inject:javax.inject:1
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
2 changes: 1 addition & 1 deletion annotations/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ abstract class BasePlugin : Plugin<Project> {
}

freeCompilerArgs.addAll(extension.kotlinCompilerArgs.get())
// We do not yet support K2, and KAPT + Kotlin 2.0 generates a warning about falling back to
// language version 1.9. Because we treat all warnings as errors, we need to suppress this
// specific warning to not fail the build. Related YT ticket:
// https://youtrack.jetbrains.com/issue/KT-68400/K2-w-Kapt-currently-doesnt-support-language-version-2.0.-Falling-back-to-1.9.
freeCompilerArgs.add("-Xsuppress-version-warnings")

fun isTestSourceSet(): Boolean {
val regex = """(?:gradle|Unit|[aA]ndroid)Test""".toRegex()
Expand Down
13 changes: 7 additions & 6 deletions compiler-api/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.symbols.IrSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
Expand Down Expand Up @@ -114,6 +115,7 @@ public class AnvilCompilationException(
message: String,
cause: Throwable? = null,
): AnvilCompilationException {
@OptIn(UnsafeDuringIrConstructionAPI::class)
return AnvilCompilationException(
message = message,
cause = cause,
Expand Down
20 changes: 11 additions & 9 deletions compiler-utils/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
com.google.dagger:dagger:2.51.1
com.squareup:kotlinpoet-jvm:1.16.0
com.squareup:kotlinpoet:1.16.0
com.google.dagger:dagger:2.52
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet:1.18.1
jakarta.inject:jakarta.inject-api:2.0.1
javax.inject:javax.inject:1
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import dagger.internal.codegen.ComponentProcessor
import dagger.internal.codegen.KspComponentProcessor
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.config.JvmTarget
import org.jetbrains.kotlin.config.LanguageVersion
import java.io.File
import java.io.OutputStream
import java.nio.file.Files
Expand All @@ -46,7 +47,7 @@ public class AnvilCompilation internal constructor(
disableComponentMerging: Boolean = false,
enableExperimentalAnvilApis: Boolean = true,
trackSourceFiles: Boolean = true,
mode: AnvilCompilationMode = Embedded(emptyList()),
mode: AnvilCompilationMode = Embedded(),
enableAnvil: Boolean = true,
): AnvilCompilation = apply {
checkNotCompiled()
Expand Down Expand Up @@ -306,7 +307,7 @@ public fun compileAnvil(
enableExperimentalAnvilApis: Boolean = true,
trackSourceFiles: Boolean = true,
previousCompilationResult: JvmCompilationResult? = null,
mode: AnvilCompilationMode = Embedded(emptyList()),
mode: AnvilCompilationMode = Embedded(),
moduleName: String? = null,
jvmTarget: JvmTarget? = null,
expectExitCode: KotlinCompilation.ExitCode? = null,
Expand All @@ -315,6 +316,8 @@ public fun compileAnvil(
return AnvilCompilation()
.apply {
kotlinCompilation.apply {
languageVersion = LanguageVersion.KOTLIN_1_9.versionString
apiVersion = LanguageVersion.KOTLIN_1_9.versionString
this.allWarningsAsErrors = allWarningsAsErrors
this.messageOutputStream = messageOutputStream
if (workingDir != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.squareup.anvil.compiler.api.CodeGenerator
public sealed class AnvilCompilationMode(public val analysisBackend: AnalysisBackend) {
public data class Embedded(
val codeGenerators: List<CodeGenerator> = emptyList(),
val useDagger: Boolean = false,
) : AnvilCompilationMode(EMBEDDED)
public data class Ksp(
val symbolProcessorProviders: List<SymbolProcessorProvider> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import dagger.Component
import dagger.Module
import dagger.Provides
import dagger.Subcomponent
import org.jetbrains.kotlin.analysis.utils.collections.mapToSet
import org.jetbrains.kotlin.utils.mapToSetOrEmpty
import kotlin.reflect.KClass

@ExperimentalAnvilApi
Expand All @@ -29,7 +29,7 @@ public fun Class<*>.moduleFactoryClass(

val providesMethods = methodsOrCompanionMethods
.filter { it.isAnnotationPresent(Provides::class.java) }
.mapToSet { it.name }
.mapToSetOrEmpty { it.name }

assertWithMessage("No @Provides methods found in $this")
.that(providesMethods)
Expand Down
22 changes: 12 additions & 10 deletions compiler/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
com.google.dagger:dagger:2.51.1
com.squareup:kotlinpoet-jvm:1.16.0
com.squareup:kotlinpoet-ksp:1.16.0
com.squareup:kotlinpoet:1.16.0
com.google.dagger:dagger:2.52
com.squareup:kotlinpoet-jvm:1.18.1
com.squareup:kotlinpoet-ksp:1.18.1
com.squareup:kotlinpoet:1.18.1
jakarta.inject:jakarta.inject-api:2.0.1
javax.annotation:jsr250-api:1.0
javax.inject:javax.inject:1
org.jetbrains.intellij.deps:trove4j:1.0.20200330
org.jetbrains.kotlin:kotlin-bom:1.9.24
org.jetbrains.kotlin:kotlin-compiler-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-daemon-embeddable:1.9.24
org.jetbrains.kotlin:kotlin-reflect:1.9.24
org.jetbrains.kotlin:kotlin-script-runtime:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-bom:2.0.21
org.jetbrains.kotlin:kotlin-compiler-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-daemon-embeddable:2.0.21
org.jetbrains.kotlin:kotlin-reflect:2.0.21
org.jetbrains.kotlin:kotlin-script-runtime:2.0.21
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.classFqName
import org.jetbrains.kotlin.ir.types.classOrFail
import org.jetbrains.kotlin.ir.types.classOrNull
Expand All @@ -49,6 +50,7 @@ import java.io.File
* as super types to Dagger components annotated with `@MergeComponent` or `@MergeSubcomponent`.
* This also supports arbitrary interface merging on interfaces annotated with `@MergeInterfaces`.
*/
@OptIn(org.jetbrains.kotlin.backend.common.extensions.FirIncompatiblePluginAPI::class)
internal class IrContributionMerger(
private val classScanner: ClassScanner,
private val moduleDescriptorFactory: RealAnvilModuleDescriptor.Factory,
Expand Down Expand Up @@ -160,6 +162,7 @@ internal class IrContributionMerger(
irMergesFile.writeText(mergedText)
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrBuilderWithScope.addMergedModules(
annotations: List<AnnotationReferenceIr>,
moduleFragment: IrModuleFragment,
Expand Down Expand Up @@ -378,6 +381,7 @@ internal class IrContributionMerger(
contributedModules: Sequence<IrClass>,
annotations: List<AnnotationReferenceIr>,
): IrConstructorCall {
@OptIn(UnsafeDuringIrConstructionAPI::class)
return irCallConstructor(
callee = pluginContext
.referenceConstructors(daggerAnnotationFqName.classIdBestGuess())
Expand Down Expand Up @@ -628,6 +632,7 @@ internal class IrContributionMerger(

// Since we are modifying the state of the code here, this does not need to be reflected in
// the associated [ClassReferenceIr] which is more of an initial snapshot.
@OptIn(UnsafeDuringIrConstructionAPI::class)
clazz.owner.superTypes += toAdd

// Return the list of added supertypes
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/main/java/com/squareup/anvil/compiler/IrUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.classifierOrNull
import org.jetbrains.kotlin.ir.types.typeOrNull
Expand Down Expand Up @@ -38,6 +39,7 @@ internal fun IrClass.requireClassId(): ClassId {
)
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal fun IrClassSymbol.requireClassId(): ClassId = owner.requireClassId()

internal val IrExpression.kclassUnwrapped: IrClassifierSymbol
Expand All @@ -53,6 +55,7 @@ internal val IrDeclarationWithName.fqName: FqName
element = this,
)

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal val IrClassSymbol.fqName: FqName get() = owner.fqName

// If we're evaluating an anonymous inner class, it cannot merge anything and will cause
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import kotlin.LazyThreadSafetyMode.NONE

internal class AnnotationArgumentReferenceIr(
Expand All @@ -25,6 +26,7 @@ internal class AnnotationArgumentReferenceIr(

// We currently special-case for Classes, but this is the spot we'll need to update if we need to
// support primitives later on.
@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun findValue(): Any {
(argumentExpression as? IrConst<*>)?.let {
return it.value as Any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.squareup.anvil.compiler.api.AnvilCompilationException
import com.squareup.anvil.compiler.internal.reference.AnnotationReference
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.getArgumentsWithIr
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.name.FqName
Expand Down Expand Up @@ -83,6 +84,7 @@ internal class AnnotationReferenceIr(
}
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal fun IrConstructorCall.toAnnotationReference(
context: IrPluginContext,
declaringClass: ClassReferenceIr?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import org.jetbrains.kotlin.backend.common.lower.parents
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.packageFqName
import org.jetbrains.kotlin.ir.util.parents
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import kotlin.LazyThreadSafetyMode.NONE

@OptIn(UnsafeDuringIrConstructionAPI::class)
internal class ClassReferenceIr(
val clazz: IrClassSymbol,
val context: IrPluginContext,
Expand All @@ -31,6 +34,7 @@ internal class ClassReferenceIr(
get() = fqName.shortName().asString()

val enclosingClassesWithSelf: List<ClassReferenceIr> by lazy {
@OptIn(UnsafeDuringIrConstructionAPI::class)
clazz.owner.parents
.filterIsInstance<IrClass>()
.map { it.symbol.toClassReference(context) }
Expand Down
2 changes: 1 addition & 1 deletion gradle-plugin/dependencies/runtimeClasspath.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
org.jetbrains.kotlin:kotlin-stdlib:1.9.24
org.jetbrains.kotlin:kotlin-stdlib:2.0.21
org.jetbrains:annotations:13.0
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ internal open class AnvilPlugin : KotlinCompilerPluginSupportPlugin {
override fun applyToCompilation(
kotlinCompilation: KotlinCompilation<*>,
): Provider<List<SubpluginOption>> {
kotlinCompilation.compilerOptions.options.let {
@Suppress("DEPRECATION")
val useK2 = it.useK2.get()
if (useK2 || it.languageVersion.getOrElse(KOTLIN_1_9) >= KOTLIN_2_0) {
kotlinCompilation.project.logger
.error(
"NOTE: Anvil is currently incompatible with the K2 compiler. Related GH issue:" +
"https://github.com/square/anvil/issues/733",
)
kotlinCompilation.compileTaskProvider.configure { action ->
action.compilerOptions.let {
@Suppress("DEPRECATION")
val useK2 = it.useK2.get()
if (useK2 || it.languageVersion.getOrElse(KOTLIN_1_9) >= KOTLIN_2_0) {
kotlinCompilation.project.logger
.warn(
"NOTE: Anvil is currently incompatible with the K2 compiler and the language " +
"version will be overridden to 1.9. Related GH issue:" +
"https://github.com/square/anvil/issues/733",
)
}

it.languageVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
it.apiVersion.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ android.defaults.buildfeatures.viewBinding=false

# Suppress the warning about MPP being in alpha.
kotlin.mpp.stability.nowarn=true

kotlin.languageVersion=1.9
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ autoService = "1.1.1"
autoValue = "1.11.0"
buildconfig = "5.4.0"
classgraph = "4.8.174"
dagger = "2.51.1"
dagger = "2.52"
dropbox-dependencyGuard = "0.5.0"
dokka = "1.9.20"
espresso = "3.5.1"
Expand All @@ -29,14 +29,14 @@ jvm-toolchain = "17"
jvm-target-library = "8"
jvm-target-minimal = "11"
kase = "0.11.1"
kct = "0.4.0"
kct = "0.5.1"
kgx = "0.1.12"
kotest = "5.9.1"
kotlin = "1.9.24"
kotlin = "2.0.21"
kotlinx-binaryCompatibility = "0.16.2"
kotlinpoet = "1.16.0"
kotlinpoet = "1.18.1"
# If updating KSP version, we currently have ksp override logic in settings.gradle that needs to be updated too
ksp = "1.9.24-1.0.20"
ksp = "2.0.21-1.0.25"
ktlint = "1.0.1"
ktlintPlugin = "12.1.1"
mavenPublish = "0.29.0"
Expand Down

0 comments on commit 78775e0

Please sign in to comment.