Skip to content

Commit 314c583

Browse files
bcorsoDagger Team
authored and
Dagger Team
committed
Update kotlin (and related dependencies) to 2.0.21.
This CL: * Updates Kotlin to 2.0.21 * Updates KSP to 2.0.21-1.0.28 * Updates kotlin-metadata-jvm to 2.0.21 * Migrates kotlin-metadata-jvm usages to the new API (the pre-2.0.0 APIs are deprecated). * Updates XProcessing and XProcessing Testing jars * Adds flags to fall back to Kotlin 1.9 for compiler tests (Working on getting these tests working with K2/KSP2 is in progress). * Updated all of our artifact tests to use the same Kotlin and KSP versions. * Added `compat_kt_jvm_library` to alias output jars to the expected locations. Fixes #4525 RELNOTES=Fixes #4525: Update kotlin-jvm-metadata to 2.0.21 to remove dependency on Beta version. PiperOrigin-RevId: 702486745
1 parent 5fd8ec1 commit 314c583

File tree

28 files changed

+364
-612
lines changed

28 files changed

+364
-612
lines changed

WORKSPACE

+5-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ http_archive(
147147

148148
load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")
149149

150-
KOTLIN_VERSION = "1.9.24"
150+
KOTLIN_VERSION = "2.0.21"
151151

152152
# Get from https://github.com/JetBrains/kotlin/releases/
153153
KOTLINC_RELEASE_SHA = "eb7b68e01029fa67bc8d060ee54c12018f2c60ddc438cf21db14517229aa693b"
@@ -203,7 +203,7 @@ GRPC_VERSION = "1.2.0"
203203

204204
INCAP_VERSION = "0.2"
205205

206-
KSP_VERSION = KOTLIN_VERSION + "-1.0.20"
206+
KSP_VERSION = KOTLIN_VERSION + "-1.0.28"
207207

208208
MAVEN_VERSION = "3.3.3"
209209

@@ -245,6 +245,8 @@ maven_install(
245245
"com.google.code.findbugs:jsr305:3.0.1",
246246
"com.google.devtools.ksp:symbol-processing:%s" % KSP_VERSION,
247247
"com.google.devtools.ksp:symbol-processing-api:%s" % KSP_VERSION,
248+
"com.google.devtools.ksp:symbol-processing-common-deps:%s" % KSP_VERSION,
249+
"com.google.devtools.ksp:symbol-processing-aa-embeddable:%s" % KSP_VERSION,
248250
"com.google.errorprone:error_prone_annotation:%s" % ERROR_PRONE_VERSION,
249251
"com.google.errorprone:error_prone_annotations:%s" % ERROR_PRONE_VERSION,
250252
"com.google.errorprone:error_prone_check_api:%s" % ERROR_PRONE_VERSION,
@@ -291,7 +293,7 @@ maven_install(
291293
"org.jetbrains.kotlin:kotlin-compiler-embeddable:%s" % KOTLIN_VERSION,
292294
"org.jetbrains.kotlin:kotlin-daemon-embeddable:%s" % KOTLIN_VERSION,
293295
"org.jetbrains.kotlin:kotlin-stdlib:%s" % KOTLIN_VERSION,
294-
"org.jetbrains.kotlin:kotlin-metadata-jvm:2.0.0-Beta5",
296+
"org.jetbrains.kotlin:kotlin-metadata-jvm:%s" % KOTLIN_VERSION,
295297
"org.jspecify:jspecify:1.0.0",
296298
"org.mockito:mockito-core:2.28.2",
297299
"org.pantsbuild:jarjar:1.7.2",

java/dagger/hilt/android/plugin/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
buildscript {
22
ext {
3-
kotlin_version = "1.9.24"
3+
kotlin_version = "2.0.21"
44
agp_version = System.getenv('AGP_VERSION') ?: "8.1.1"
5-
ksp_version = "$kotlin_version-1.0.20"
5+
ksp_version = "$kotlin_version-1.0.28"
66
pluginArtifactId = 'hilt-android-gradle-plugin'
77
pluginId = 'com.google.dagger.hilt.android'
88
}

java/dagger/hilt/android/testing/compile/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ java_library(
4141
"//java/dagger/hilt/processor/internal/uninstallmodules:processor_lib",
4242
"//java/dagger/internal/codegen:processor",
4343
"//java/dagger/internal/codegen/extension",
44-
"//java/dagger/internal/codegen/xprocessing",
4544
"//java/dagger/internal/codegen/xprocessing:xprocessing-testing",
4645
"//java/dagger/testing/compile",
4746
"//third_party/java/auto:value",

java/dagger/hilt/android/testing/compile/HiltCompilerTests.java

+16-7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@
7070

7171
/** {@link Compiler} instances for testing Android Hilt. */
7272
public final class HiltCompilerTests {
73+
private static final ImmutableList<String> DEFAULT_JAVAC_OPTIONS = ImmutableList.of();
74+
75+
private static final ImmutableList<String> DEFAULT_KOTLINC_OPTIONS =
76+
ImmutableList.of(
77+
"-api-version=1.9",
78+
"-language-version=1.9",
79+
"-P", "plugin:org.jetbrains.kotlin.kapt3:correctErrorTypes=true");
80+
7381
/** Returns the {@link XProcessingEnv.Backend} for the given {@link CompilationResultSubject}. */
7482
public static XProcessingEnv.Backend backend(CompilationResultSubject subject) {
7583
return CompilerTests.backend(subject);
@@ -161,9 +169,8 @@ public static void compileWithKapt(
161169
sources,
162170
/* classpath= */ ImmutableList.of(CompilerTests.compilerDepsJar()),
163171
/* inheritClasspath= */ false,
164-
/* javacArguments= */ ImmutableList.of(),
165-
/* kotlincArguments= */ ImmutableList.of(
166-
),
172+
/* javacArguments= */ DEFAULT_JAVAC_OPTIONS,
173+
/* kotlincArguments= */ DEFAULT_KOTLINC_OPTIONS,
167174
/* kaptProcessors= */ ImmutableList.<Processor>builder()
168175
.addAll(defaultProcessors())
169176
.addAll(additionalProcessors)
@@ -275,10 +282,12 @@ public void compile(Consumer<CompilationResultSubject> onCompilationResult) {
275282
sources().asList(),
276283
/* classpath= */ ImmutableList.of(CompilerTests.compilerDepsJar()),
277284
/* options= */ processorOptions(),
278-
/* javacArguments= */ javacArguments().asList(),
279-
/* kotlincArguments= */ ImmutableList.of(
280-
"-P",
281-
"plugin:org.jetbrains.kotlin.kapt3:correctErrorTypes=true"),
285+
/* javacArguments= */
286+
ImmutableList.<String>builder()
287+
.addAll(DEFAULT_JAVAC_OPTIONS)
288+
.addAll(javacArguments())
289+
.build(),
290+
/* kotlincArguments= */ DEFAULT_KOTLINC_OPTIONS,
282291
/* config= */ HiltProcessingEnvConfigs.CONFIGS,
283292
/* javacProcessors= */ ImmutableList.<Processor>builder()
284293
.addAll(mergeProcessors(defaultProcessors(), additionalJavacProcessors()))

java/dagger/hilt/processor/internal/kotlin/BUILD

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
# Description:
1616
# Sources related to Kotlin metadata.
1717

18-
load("@rules_java//java:defs.bzl", "java_library")
18+
load("//tools:bazel_compat.bzl", "compat_kt_jvm_library")
1919

2020
package(default_visibility = ["//:src"])
2121

22-
java_library(
22+
compat_kt_jvm_library(
2323
name = "kotlin",
24-
srcs = glob(["*.java"]),
24+
srcs = glob([
25+
"*.java",
26+
"*.kt",
27+
]),
2528
deps = [
2629
"//:dagger_with_compiler",
2730
"//java/dagger/hilt/processor/internal:classnames",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright (C) 2023 The Dagger Authors.
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+
package dagger.hilt.processor.internal.kotlin
18+
19+
import androidx.room.compiler.processing.XAnnotation
20+
import androidx.room.compiler.processing.XFieldElement
21+
import androidx.room.compiler.processing.XMethodElement
22+
import androidx.room.compiler.processing.XTypeElement
23+
import kotlin.Metadata
24+
import kotlin.metadata.declaresDefaultValue
25+
import kotlin.metadata.KmClass
26+
import kotlin.metadata.KmConstructor
27+
import kotlin.metadata.KmFunction
28+
import kotlin.metadata.KmProperty
29+
import kotlin.metadata.KmValueParameter
30+
import kotlin.metadata.jvm.KotlinClassMetadata
31+
import kotlin.metadata.jvm.fieldSignature
32+
import kotlin.metadata.jvm.getterSignature
33+
import kotlin.metadata.jvm.signature
34+
import kotlin.metadata.jvm.syntheticMethodForAnnotations
35+
36+
/** Container classes for kotlin metadata types. */
37+
class ClassMetadata private constructor(private val kmClass: KmClass) {
38+
val functionsBySignature = buildList<FunctionMetadata> {
39+
addAll(kmClass.constructors.map { ConstructorMetadata(it) })
40+
addAll(kmClass.functions.map { MethodMetadata(it) })
41+
}.associateBy { it.signature }
42+
43+
val propertiesBySignature =
44+
kmClass.properties
45+
.filter { it.fieldSignature != null }
46+
.map { PropertyMetadata(it) }
47+
.associateBy { it.fieldSignature }
48+
49+
fun constructors(): List<FunctionMetadata> =
50+
functionsBySignature.values.filterIsInstance<ConstructorMetadata>()
51+
52+
companion object {
53+
/** Parse Kotlin class metadata from a given type element. */
54+
@JvmStatic
55+
fun of(typeElement: XTypeElement): ClassMetadata {
56+
val metadataAnnotation = checkNotNull(typeElement.getAnnotation(Metadata::class)).value
57+
return when (val classMetadata = KotlinClassMetadata.readStrict(metadataAnnotation)) {
58+
is KotlinClassMetadata.Class -> ClassMetadata(classMetadata.kmClass)
59+
else -> error("Unsupported metadata type: ${classMetadata}")
60+
}
61+
}
62+
}
63+
}
64+
65+
class ConstructorMetadata(private val kmConstructor: KmConstructor) : FunctionMetadata {
66+
override val name = "<init>"
67+
override val signature = kmConstructor.signature!!.toString()
68+
override val parameters = kmConstructor.valueParameters.map { ParameterMetadata(it) }
69+
}
70+
71+
class MethodMetadata(private val kmFunction: KmFunction) : FunctionMetadata {
72+
override val name = kmFunction.name
73+
override val signature = kmFunction.signature!!.toString()
74+
override val parameters = kmFunction.valueParameters.map { ParameterMetadata(it) }
75+
}
76+
77+
interface FunctionMetadata {
78+
val name: String
79+
val signature: String
80+
val parameters: List<ParameterMetadata>
81+
}
82+
83+
class PropertyMetadata(private val kmProperty: KmProperty) {
84+
val name = kmProperty.name
85+
86+
/** Returns the JVM field descriptor of the backing field of this property. */
87+
val fieldSignature = kmProperty.fieldSignature?.toString()
88+
89+
val getterSignature = kmProperty.getterSignature?.toString()
90+
91+
/** Returns JVM method descriptor of the synthetic method for property annotations. */
92+
val methodForAnnotationsSignature = kmProperty.syntheticMethodForAnnotations?.toString()
93+
}
94+
95+
class ParameterMetadata(private val kmValueParameter: KmValueParameter) {
96+
val name = kmValueParameter.name
97+
98+
fun declaresDefaultValue() = kmValueParameter.declaresDefaultValue
99+
}
100+

0 commit comments

Comments
 (0)