From 57c0e35adb44ef3833758bd7a0cfcae5f49c4ff6 Mon Sep 17 00:00:00 2001 From: Ralf Wondratschek Date: Fri, 14 Aug 2020 11:37:05 -0700 Subject: [PATCH] Upgrade all modules except for the gradle-plugin to Kotlin 1.4.10. --- .github/workflows/ci.yml | 4 ++-- compiler/build.gradle | 12 ++++-------- .../anvil/compiler/codegen/BindingModuleGenerator.kt | 1 - .../dagger/InjectConstructorFactoryGenerator.kt | 3 +-- .../codegen/dagger/MembersInjectorGenerator.kt | 1 - .../codegen/dagger/ProvidesMethodFactoryGenerator.kt | 1 - .../java/com/squareup/anvil/compiler/TestUtils.kt | 8 -------- .../compiler/dagger/MembersInjectorGeneratorTest.kt | 2 +- dependencies.gradle | 9 ++++++++- gradle-plugin/build.gradle | 8 ++++---- sample/library/build.gradle | 7 ------- .../java/com/squareup/anvil/sample/Description.kt | 11 +++-------- 12 files changed, 23 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f4070000..e234f3f9a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: # solution. fail-fast: false matrix: - kotlin-version: [1.3.72, 1.4.10, 1.4.20-RC] + kotlin-version: [1.4.10, 1.4.20-RC] steps: - uses: actions/checkout@v2 @@ -142,7 +142,7 @@ jobs: # solution. fail-fast: false matrix: - kotlin-version: [1.3.72, 1.4.10] + kotlin-version: [1.4.10] steps: - uses: actions/checkout@v2 diff --git a/compiler/build.gradle b/compiler/build.gradle index 02a94f5f1..3bc765463 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -31,13 +31,9 @@ if (rootProject.ext.kotlinIrSupported) { tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8 - freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" - - // TODO: remove the if-check when upgrading to Kotlin 1.4. - if (rootProject.ext.kotlinVersion.startsWith('1.4')) { - // The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin - // compiler requires this flag when doing so. - freeCompilerArgs += "-Xjvm-default=enable" - } + + // The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin + // compiler requires this flag when doing so. + freeCompilerArgs += "-Xjvm-default=enable" } } diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt index df5b5f8c3..8f78810cc 100644 --- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt +++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/BindingModuleGenerator.kt @@ -145,7 +145,6 @@ internal class BindingModuleGenerator( .toList() } - @OptIn(ExperimentalStdlibApi::class) override fun flush( codeGenDir: File, module: ModuleDescriptor diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/InjectConstructorFactoryGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/InjectConstructorFactoryGenerator.kt index 7d9bdf433..5c0070186 100644 --- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/InjectConstructorFactoryGenerator.kt +++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/InjectConstructorFactoryGenerator.kt @@ -50,7 +50,6 @@ internal class InjectConstructorFactoryGenerator : PrivateCodeGenerator() { } } - @OptIn(ExperimentalStdlibApi::class) private fun generateFactoryClass( codeGenDir: File, module: ModuleDescriptor, @@ -60,7 +59,7 @@ internal class InjectConstructorFactoryGenerator : PrivateCodeGenerator() { val packageName = clazz.containingKtFile.packageFqName.asString() val className = "${clazz.generateClassName()}_Factory" - val parameters = constructor.getValueParameters().mapToParameter(module) + val parameters = constructor.valueParameters.mapToParameter(module) val typeParameters = clazz.typeParameterList ?.parameters diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt index a4d5e6fb9..b07b5d3db 100644 --- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt +++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/MembersInjectorGenerator.kt @@ -61,7 +61,6 @@ internal class MembersInjectorGenerator : PrivateCodeGenerator() { } } - @OptIn(ExperimentalStdlibApi::class) private fun generateMembersInjectorClass( codeGenDir: File, module: ModuleDescriptor, diff --git a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/ProvidesMethodFactoryGenerator.kt b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/ProvidesMethodFactoryGenerator.kt index 5a91c36c2..7c86c7387 100644 --- a/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/ProvidesMethodFactoryGenerator.kt +++ b/compiler/src/main/java/com/squareup/anvil/compiler/codegen/dagger/ProvidesMethodFactoryGenerator.kt @@ -90,7 +90,6 @@ internal class ProvidesMethodFactoryGenerator : PrivateCodeGenerator() { } } - @OptIn(ExperimentalStdlibApi::class) private fun generateFactoryClass( codeGenDir: File, module: ModuleDescriptor, diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/TestUtils.kt b/compiler/src/test/java/com/squareup/anvil/compiler/TestUtils.kt index 946a966df..0d4c48cf0 100644 --- a/compiler/src/test/java/com/squareup/anvil/compiler/TestUtils.kt +++ b/compiler/src/test/java/com/squareup/anvil/compiler/TestUtils.kt @@ -116,14 +116,12 @@ internal val Result.innerModule: Class<*> internal val Result.injectClass: Class<*> get() = classLoader.loadClass("com.squareup.test.InjectClass") -@OptIn(ExperimentalStdlibApi::class) internal val Class<*>.hintContributes: KClass<*>? get() = contributedProperties(HINT_CONTRIBUTES_PACKAGE_PREFIX) ?.filter { it.java == this } ?.also { assertThat(it.size).isEqualTo(1) } ?.first() -@OptIn(ExperimentalStdlibApi::class) internal val Class<*>.hintContributesScope: KClass<*>? get() = contributedProperties(HINT_CONTRIBUTES_PACKAGE_PREFIX) ?.also { assertThat(it.size).isEqualTo(2) } @@ -131,14 +129,12 @@ internal val Class<*>.hintContributesScope: KClass<*>? ?.also { assertThat(it.size).isEqualTo(1) } ?.first() -@OptIn(ExperimentalStdlibApi::class) internal val Class<*>.hintBinding: KClass<*>? get() = contributedProperties(HINT_BINDING_PACKAGE_PREFIX) ?.filter { it.java == this } ?.also { assertThat(it.size).isEqualTo(1) } ?.first() -@OptIn(ExperimentalStdlibApi::class) internal val Class<*>.hintBindingScope: KClass<*>? get() = contributedProperties(HINT_BINDING_PACKAGE_PREFIX) ?.also { assertThat(it.size).isEqualTo(2) } @@ -146,7 +142,6 @@ internal val Class<*>.hintBindingScope: KClass<*>? ?.also { assertThat(it.size).isEqualTo(1) } ?.first() -@OptIn(ExperimentalStdlibApi::class) internal fun Class<*>.moduleFactoryClass( providerMethodName: String, companion: Boolean = false @@ -160,14 +155,12 @@ internal fun Class<*>.moduleFactoryClass( ) } -@OptIn(ExperimentalStdlibApi::class) internal fun Class<*>.factoryClass(): Class<*> { val enclosingClassString = enclosingClass?.let { "${it.simpleName}_" } ?: "" return classLoader.loadClass("${`package`.name}.$enclosingClassString${simpleName}_Factory") } -@OptIn(ExperimentalStdlibApi::class) internal fun Class<*>.membersInjector(): Class<*> { val enclosingClassString = enclosingClass?.let { "${it.simpleName}_" } ?: "" @@ -175,7 +168,6 @@ internal fun Class<*>.membersInjector(): Class<*> { "$enclosingClassString${simpleName}_MembersInjector") } -@OptIn(ExperimentalStdlibApi::class) private fun Class<*>.contributedProperties(packagePrefix: String): List>? { // The capitalize() doesn't make sense, I don't know where this is coming from. Maybe it's a // bug in the compile testing library? diff --git a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt index 8c89b9eaa..ef0ea2cea 100644 --- a/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt +++ b/compiler/src/test/java/com/squareup/anvil/compiler/dagger/MembersInjectorGeneratorTest.kt @@ -166,6 +166,7 @@ public final class InjectClass_MembersInjector implements MembersInjector { "b" }, Provider { listOf("c") }, @@ -675,7 +676,6 @@ public final class InjectClass_MembersInjector implements MembersInject } } - @OptIn(ExperimentalStdlibApi::class) private fun Class<*>.staticInjectMethod(memberName: String): Method { // We can't check the @InjectedFieldSignature annotation unfortunately, because it has class // retention. diff --git a/dependencies.gradle b/dependencies.gradle index c1047b4db..e9f385219 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -5,7 +5,7 @@ ext { daggerVersion = '2.28' espressoVersion = '3.2.0' kotlinVersion = project.hasProperty('square.kotlinVersion') ? - project.getProperty('square.kotlinVersion') : '1.3.72' + project.getProperty('square.kotlinVersion') : '1.4.10' kotlinUseIR = (project.hasProperty('square.useIR') ? project.getProperty('square.useIR') : 'false').toBoolean() @@ -70,6 +70,13 @@ ext { stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion", ], + // Required until Gradle uses Kotlin 1.4. + kotlin_gradle: [ + gradle_plugin: "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72", + gradle_plugin_api: "org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.3.72", + stdlib: "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72", + ], + kotlinpoet: "com.squareup:kotlinpoet:1.7.2", truth: "com.google.truth:truth:1.0.1", diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index aa878ac15..d57ef769a 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -15,7 +15,7 @@ buildscript { } dependencies { - classpath deps.kotlin.gradle_plugin + classpath deps.kotlin_gradle.gradle_plugin classpath deps.maven_publishing_plugin classpath deps.gradle_publishing_plugin classpath deps.ktlint_plugin @@ -76,9 +76,9 @@ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { } dependencies { - implementation deps.kotlin.gradle_plugin - implementation deps.kotlin.gradle_plugin_api - implementation deps.kotlin.stdlib + implementation deps.kotlin_gradle.gradle_plugin + implementation deps.kotlin_gradle.gradle_plugin_api + implementation deps.kotlin_gradle.stdlib // Compile only so that Java / Kotlin modules don't download it unnecessarily. compileOnly deps.android_gradle_plugin diff --git a/sample/library/build.gradle b/sample/library/build.gradle index 014f4477f..940efc763 100644 --- a/sample/library/build.gradle +++ b/sample/library/build.gradle @@ -18,10 +18,3 @@ dependencies { api deps.dagger2.dagger api deps.kotlin.stdlib } - -//noinspection UnnecessaryQualifiedReference -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" - } -} diff --git a/sample/library/src/main/java/com/squareup/anvil/sample/Description.kt b/sample/library/src/main/java/com/squareup/anvil/sample/Description.kt index a20e1fef7..749528caa 100644 --- a/sample/library/src/main/java/com/squareup/anvil/sample/Description.kt +++ b/sample/library/src/main/java/com/squareup/anvil/sample/Description.kt @@ -6,7 +6,6 @@ import com.squareup.scopes.ComponentHolder import java.util.Locale object Description { - @OptIn(ExperimentalStdlibApi::class) fun of(god: God): String { val name = god.name.toLowerCase(Locale.US) .capitalize(Locale.US) @@ -16,12 +15,8 @@ object Description { MOTHER -> "daughter" } - return "$name, $child of ${ - ComponentHolder.component() - .fatherProvider() - .father(god)} and ${ - ComponentHolder.component() - .motherProvider() - .mother(god)}" + return "$name, $child of " + + "${ComponentHolder.component().fatherProvider().father(god)} and " + + ComponentHolder.component().motherProvider().mother(god) } }