diff options
Diffstat (limited to 'java/dagger/hilt/android/plugin')
25 files changed, 835 insertions, 724 deletions
diff --git a/java/dagger/hilt/android/plugin/agp-wrapper-7-0/build.gradle b/java/dagger/hilt/android/plugin/agp-wrapper-7-0/build.gradle index 3c0349565..5509261c5 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper-7-0/build.gradle +++ b/java/dagger/hilt/android/plugin/agp-wrapper-7-0/build.gradle @@ -2,8 +2,10 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -kotlin { - jvmToolchain(11) +compileKotlin { + kotlinOptions { + jvmTarget = 11 + } } dependencies { diff --git a/java/dagger/hilt/android/plugin/agp-wrapper-7-1/build.gradle b/java/dagger/hilt/android/plugin/agp-wrapper-7-1/build.gradle index 5bc8d3d1c..982949a49 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper-7-1/build.gradle +++ b/java/dagger/hilt/android/plugin/agp-wrapper-7-1/build.gradle @@ -2,8 +2,10 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -kotlin { - jvmToolchain(11) +compileKotlin { + kotlinOptions { + jvmTarget = 11 + } } dependencies { diff --git a/java/dagger/hilt/android/plugin/agp-wrapper-7-2/build.gradle b/java/dagger/hilt/android/plugin/agp-wrapper-7-2/build.gradle index a41330196..e0331c2a8 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper-7-2/build.gradle +++ b/java/dagger/hilt/android/plugin/agp-wrapper-7-2/build.gradle @@ -2,8 +2,10 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -kotlin { - jvmToolchain(11) +compileKotlin { + kotlinOptions { + jvmTarget = 11 + } } dependencies { diff --git a/java/dagger/hilt/android/plugin/agp-wrapper-impl/build.gradle b/java/dagger/hilt/android/plugin/agp-wrapper-impl/build.gradle index 3ad558a8a..f270efb9f 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper-impl/build.gradle +++ b/java/dagger/hilt/android/plugin/agp-wrapper-impl/build.gradle @@ -2,8 +2,10 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -kotlin { - jvmToolchain(11) +compileKotlin { + kotlinOptions { + jvmTarget = 11 + } } dependencies { diff --git a/java/dagger/hilt/android/plugin/agp-wrapper/build.gradle b/java/dagger/hilt/android/plugin/agp-wrapper/build.gradle index 71ea72424..d8238e8f1 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper/build.gradle +++ b/java/dagger/hilt/android/plugin/agp-wrapper/build.gradle @@ -2,8 +2,10 @@ plugins { id 'org.jetbrains.kotlin.jvm' } -kotlin { - jvmToolchain(11) +compileKotlin { + kotlinOptions { + jvmTarget = 11 + } } dependencies { diff --git a/java/dagger/hilt/android/plugin/agp-wrapper/src/main/kotlin/dagger/hilt/android/plugin/util/ComponentCompat.kt b/java/dagger/hilt/android/plugin/agp-wrapper/src/main/kotlin/dagger/hilt/android/plugin/util/ComponentCompat.kt index acc59e79d..1f0d589a2 100644 --- a/java/dagger/hilt/android/plugin/agp-wrapper/src/main/kotlin/dagger/hilt/android/plugin/util/ComponentCompat.kt +++ b/java/dagger/hilt/android/plugin/agp-wrapper/src/main/kotlin/dagger/hilt/android/plugin/util/ComponentCompat.kt @@ -20,6 +20,8 @@ import com.android.build.api.instrumentation.AsmClassVisitorFactory import com.android.build.api.instrumentation.FramesComputationMode import com.android.build.api.instrumentation.InstrumentationParameters import com.android.build.api.instrumentation.InstrumentationScope +import java.io.File +import org.gradle.api.Project /** * Compatibility version of [com.android.build.api.variant.Component] diff --git a/java/dagger/hilt/android/plugin/build.gradle b/java/dagger/hilt/android/plugin/build.gradle index 869d88516..685ea7e37 100644 --- a/java/dagger/hilt/android/plugin/build.gradle +++ b/java/dagger/hilt/android/plugin/build.gradle @@ -1,8 +1,8 @@ buildscript { ext { - kotlin_version = "1.8.20" + kotlin_version = "1.9.20" agp_version = System.getenv('AGP_VERSION') ?: "7.2.0" - ksp_version = "$kotlin_version-1.0.11" + ksp_version = "$kotlin_version-1.0.14" pluginArtifactId = 'hilt-android-gradle-plugin' pluginId = 'com.google.dagger.hilt.android' } @@ -24,7 +24,12 @@ allprojects { mavenCentral() } } + +// Avoids conflict with BUILD file +project.buildDir = 'buildOut' + subprojects { + project.buildDir = 'buildOut' afterEvaluate { dependencies { // This is needed to align older versions of kotlin-stdlib. diff --git a/java/dagger/hilt/android/plugin/main/build.gradle b/java/dagger/hilt/android/plugin/main/build.gradle index 96a28b937..035ecea22 100644 --- a/java/dagger/hilt/android/plugin/main/build.gradle +++ b/java/dagger/hilt/android/plugin/main/build.gradle @@ -65,16 +65,16 @@ dependencies { compileOnly "com.android.tools.build:gradle:$agp_version" compileOnly "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" compileOnly "com.google.devtools.ksp:symbol-processing-gradle-plugin:$ksp_version" - implementation 'org.ow2.asm:asm:9.0' + implementation 'org.ow2.asm:asm:9.6' implementation "com.squareup:javapoet:1.13.0" testImplementation gradleTestKit() testImplementation 'junit:junit:4.12' testImplementation 'com.google.truth:truth:1.0.1' testImplementation 'org.javassist:javassist:3.26.0-GA' - testPluginCompile 'com.android.tools.build:gradle:7.1.2' - testPluginCompile 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0' - testPluginCompile 'com.google.devtools.ksp:symbol-processing-gradle-plugin:1.8.0-1.0.9' + testPluginCompile "com.android.tools.build:gradle:$agp_version" + testPluginCompile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + testPluginCompile "com.google.devtools.ksp:symbol-processing-gradle-plugin:$ksp_version" } // Configure the generating task of plugin-under-test-metadata.properties to @@ -85,14 +85,11 @@ tasks.withType(PluginUnderTestMetadata.class).named("pluginUnderTestMetadata").c it.pluginClasspath.from(configurations.testPluginCompile) } -kotlin { - jvmToolchain(11) -} - compileKotlin { kotlinOptions { allWarningsAsErrors = true freeCompilerArgs += [ "-opt-in=kotlin.ExperimentalStdlibApi" ] + jvmTarget = 11 } } diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/AndroidEntryPointClassVisitor.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/AndroidEntryPointClassVisitor.kt index da5fb3c3c..16e4af9c0 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/AndroidEntryPointClassVisitor.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/AndroidEntryPointClassVisitor.kt @@ -36,15 +36,10 @@ import org.objectweb.asm.Opcodes class AndroidEntryPointClassVisitor( private val apiVersion: Int, nextClassVisitor: ClassVisitor, - private val additionalClasses: File + private val classContext: ClassContext ) : ClassVisitor(apiVersion, nextClassVisitor) { - interface AndroidEntryPointParams : InstrumentationParameters { - @get:Internal - val additionalClassesDir: Property<File> - } - - abstract class Factory : AsmClassVisitorFactory<AndroidEntryPointParams> { + abstract class Factory : AsmClassVisitorFactory<InstrumentationParameters.None> { override fun createClassVisitor( classContext: ClassContext, nextClassVisitor: ClassVisitor @@ -52,7 +47,7 @@ class AndroidEntryPointClassVisitor( return AndroidEntryPointClassVisitor( apiVersion = instrumentationContext.apiVersion.get(), nextClassVisitor = nextClassVisitor, - additionalClasses = parameters.get().additionalClassesDir.get() + classContext = classContext ) } @@ -198,34 +193,21 @@ class AndroidEntryPointClassVisitor( } /** - * Check if Hilt generated class is a BroadcastReceiver with the marker field which means + * Check if Hilt generated class is a BroadcastReceiver with the marker annotation which means * a super.onReceive invocation has to be inserted in the implementation. */ - private fun hasOnReceiveBytecodeInjectionMarker() = - findAdditionalClassFile(newSuperclassName).inputStream().use { - var hasMarker = false - ClassReader(it).accept( - object : ClassVisitor(apiVersion) { - override fun visitField( - access: Int, - name: String, - descriptor: String, - signature: String?, - value: Any? - ): FieldVisitor? { - if (name == "onReceiveBytecodeInjectionMarker") { - hasMarker = true - } - return null - } - }, - ClassReader.SKIP_CODE or ClassReader.SKIP_DEBUG or ClassReader.SKIP_FRAMES - ) - return@use hasMarker - } + private fun hasOnReceiveBytecodeInjectionMarker(): Boolean { + val newSuperclassFQName = newSuperclassName.toFQName() + return classContext.loadClassData(newSuperclassFQName) + ?.classAnnotations?.contains(ON_RECEIVE_MARKER_ANNOTATION) + ?: error("Cannot load class $newSuperclassFQName!") + } - private fun findAdditionalClassFile(className: String) = - File(additionalClasses, "$className.class") + /** + * Return a fully qualified name from an internal name. + * See https://asm.ow2.io/javadoc/org/objectweb/asm/Type.html#getInternalName() + */ + private fun String.toFQName() = this.replace('/', '.') companion object { val ANDROID_ENTRY_POINT_ANNOTATIONS = setOf( @@ -235,5 +217,6 @@ class AndroidEntryPointClassVisitor( const val ON_RECEIVE_METHOD_NAME = "onReceive" const val ON_RECEIVE_METHOD_DESCRIPTOR = "(Landroid/content/Context;Landroid/content/Intent;)V" + const val ON_RECEIVE_MARKER_ANNOTATION = "dagger.hilt.android.internal.OnReceiveBytecodeInjectionMarker" } } diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt index 4e2b8788a..7b03e434a 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/HiltGradlePlugin.kt @@ -38,7 +38,6 @@ import dagger.hilt.android.plugin.util.getKaptConfigName import dagger.hilt.android.plugin.util.getKspConfigName import dagger.hilt.android.plugin.util.isKspTask import dagger.hilt.processor.internal.optionvalues.GradleProjectType -import java.io.File import javax.inject.Inject import org.gradle.api.JavaVersion import org.gradle.api.Plugin @@ -246,12 +245,9 @@ class HiltGradlePlugin @Inject constructor( fun registerTransform(androidComponent: ComponentCompat) { androidComponent.transformClassesWith( classVisitorFactoryImplClass = AndroidEntryPointClassVisitor.Factory::class.java, - scope = InstrumentationScope.PROJECT - ) { params -> - val classesDir = - File(project.buildDir, "intermediates/javac/${androidComponent.name}/classes") - params.additionalClassesDir.set(classesDir) - } + scope = InstrumentationScope.PROJECT, + instrumentationParamsConfig = {} + ) androidComponent.setAsmFramesComputationMode( FramesComputationMode.COMPUTE_FRAMES_FOR_INSTRUMENTED_METHODS ) diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/CopyTransform.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/CopyTransform.kt index 7c8326b0f..f7c33dca4 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/CopyTransform.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/CopyTransform.kt @@ -16,7 +16,6 @@ package dagger.hilt.android.plugin.util -import org.gradle.api.artifacts.transform.CacheableTransform import org.gradle.api.artifacts.transform.InputArtifact import org.gradle.api.artifacts.transform.TransformAction import org.gradle.api.artifacts.transform.TransformOutputs @@ -24,12 +23,13 @@ import org.gradle.api.artifacts.transform.TransformParameters import org.gradle.api.file.FileSystemLocation import org.gradle.api.provider.Provider import org.gradle.api.tasks.Classpath +import org.gradle.work.DisableCachingByDefault /** * A transform that registers the input file (usually a jar or a class) as an output and thus * changing from one artifact type to another. */ -@CacheableTransform +@DisableCachingByDefault(because = "Copying files does not benefit from caching") abstract class CopyTransform : TransformAction<TransformParameters.None> { @get:Classpath @get:InputArtifact diff --git a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/Tasks.kt b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/Tasks.kt index 2c803b71a..a91ce35c6 100644 --- a/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/Tasks.kt +++ b/java/dagger/hilt/android/plugin/main/src/main/kotlin/dagger/hilt/android/plugin/util/Tasks.kt @@ -38,8 +38,20 @@ internal fun addKaptTaskProcessorOptions( component: ComponentCompat, produceArgProvider: (Task) -> CommandLineArgumentProvider ) = project.plugins.withId("kotlin-kapt") { + checkClass("org.jetbrains.kotlin.gradle.internal.KaptTask") { + """ + The KAPT plugin was detected to be applied but its task class could not be found. + + This is an indicator that the Hilt Gradle Plugin is using a different class loader because + it was declared at the root while KAPT was declared in a sub-project. To fix this, declare + both plugins in the same scope, i.e. either at the root (without applying them) or at the + sub-projects. + """.trimIndent() + } project.tasks.withType(KaptTask::class.java) { task -> - if (task.name == "kapt${component.name.capitalize()}Kotlin") { + if (task.name == "kapt${component.name.capitalize()}Kotlin" || + // Task names in shared/src/AndroidMain in KMP projects has a platform suffix. + task.name == "kapt${component.name.capitalize()}KotlinAndroid") { val argProvider = produceArgProvider.invoke(task) // TODO: Update once KT-58009 is fixed. try { @@ -60,16 +72,39 @@ internal fun addKspTaskProcessorOptions( component: ComponentCompat, produceArgProvider: (Task) -> CommandLineArgumentProvider ) = project.plugins.withId("com.google.devtools.ksp") { + checkClass("com.google.devtools.ksp.gradle.KspTaskJvm") { + """ + The KSP plugin was detected to be applied but its task class could not be found. + + This is an indicator that the Hilt Gradle Plugin is using a different class loader because + it was declared at the root while KSP was declared in a sub-project. To fix this, declare + both plugins in the same scope, i.e. either at the root (without applying them) or at the + sub-projects. + + See https://github.com/google/dagger/issues/3965 for more details. + """.trimIndent() + } project.tasks.withType(KspTaskJvm::class.java) { task -> - if (task.name == "ksp${component.name.capitalize()}Kotlin") { + if (task.name == "ksp${component.name.capitalize()}Kotlin" || + // Task names in shared/src/AndroidMain in KMP projects has a platform suffix. + task.name == "ksp${component.name.capitalize()}KotlinAndroid") { task.commandLineArgumentProviders.add(produceArgProvider.invoke(task)) } } } +private inline fun checkClass(fqn: String, msg: () -> String) { + try { + Class.forName(fqn) + } catch (ex: ClassNotFoundException) { + throw IllegalStateException(msg.invoke(), ex) + } +} + internal fun Task.isKspTask(): Boolean = try { val kspTaskClass = Class.forName("com.google.devtools.ksp.gradle.KspTask") kspTaskClass.isAssignableFrom(this::class.java) } catch (ex: ClassNotFoundException) { false -}
\ No newline at end of file +} + diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryA/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryA/build.gradle index e0ec23097..9e8a097b2 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryA/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryA/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" defaultConfig { minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 1 versionName "1.0" } diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryC/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryC/build.gradle index 68c6a97f3..450f128aa 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryC/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/android-libraryC/build.gradle @@ -4,12 +4,12 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" defaultConfig { minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 1 versionName "1.0" } diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/app/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/app/build.gradle index 23cd028b9..954e209d9 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/app/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/app/build.gradle @@ -20,8 +20,8 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" flavorDimensions 'api', 'version' productFlavors { @@ -46,7 +46,7 @@ android { defaultConfig { applicationId "simple.app" minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 } compileOptions { diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/feature/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/feature/build.gradle index 8e3495156..068d402fa 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/feature/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/flavored-project/feature/build.gradle @@ -20,8 +20,8 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" flavorDimensions 'api', 'version' productFlavors { @@ -45,7 +45,7 @@ android { defaultConfig { minSdkVersion 16 - targetSdkVersion 32 + targetSdkVersion 33 } compileOptions { diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/build.gradle index 2173a8280..506d40a81 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/build.gradle @@ -20,13 +20,13 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + namespace "simple.app" defaultConfig { applicationId "simple.app" minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 } compileOptions { diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/AndroidManifest.xml b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/AndroidManifest.xml index da45ecc46..ce521fba8 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/AndroidManifest.xml +++ b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/AndroidManifest.xml @@ -16,5 +16,7 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="simple.app"> <application android:name=".SimpleApp" android:label="Flavored App"> + <receiver android:name=".SimpleReceiver" android:exported="false"> + </receiver> </application> </manifest>
\ No newline at end of file diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/java/simple/app/SimpleReceiver.java b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/java/simple/app/SimpleReceiver.java new file mode 100644 index 000000000..ce483add8 --- /dev/null +++ b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/app/src/main/java/simple/app/SimpleReceiver.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package simple.app; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import dagger.hilt.android.AndroidEntryPoint; + +@AndroidEntryPoint +class SimpleReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) {} +} diff --git a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/feature/build.gradle b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/feature/build.gradle index e19f1d571..57f7a742b 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/feature/build.gradle +++ b/java/dagger/hilt/android/plugin/main/src/test/data/simple-project-for-agp-test/feature/build.gradle @@ -20,12 +20,12 @@ plugins { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + namespace "simple.library" defaultConfig { minSdkVersion 16 - targetSdkVersion 32 + targetSdkVersion 33 } compileOptions { diff --git a/java/dagger/hilt/android/plugin/main/src/test/kotlin/AGPCompatibilityTest.kt b/java/dagger/hilt/android/plugin/main/src/test/kotlin/AGPCompatibilityTest.kt index d5bc48802..f488fb332 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/kotlin/AGPCompatibilityTest.kt +++ b/java/dagger/hilt/android/plugin/main/src/test/kotlin/AGPCompatibilityTest.kt @@ -26,11 +26,13 @@ import org.junit.rules.TemporaryFolder import org.junit.runner.RunWith import org.junit.runners.Parameterized -const val TASK = ":app:hiltJavaCompileDebug" +// `hiltJavaCompileDebug` gets to run as well as `transformDebugClassesWithAsm` depends on it. +const val TASK = ":app:transformDebugClassesWithAsm" @RunWith(Parameterized::class) class AGPCompatibilityTest( - private val agpVersion: String + private val agpVersion: String, + private val gradleVersion: String ) { @get:Rule val testProjectDir = TemporaryFolder() @@ -75,18 +77,21 @@ class AGPCompatibilityTest( GradleRunner.create() .withProjectDir(testProjectDir.root) .withArguments(*args) + .withGradleVersion(gradleVersion) .forwardOutput() return gradleRunner.build() } companion object { @JvmStatic - @Parameterized.Parameters(name = "agpVersion = {0}") + @Parameterized.Parameters(name = "agpVersion = {0}, gradleVersion = {1}") fun parameters() = listOf( - arrayOf("7.2.0"), - arrayOf("7.1.0"), - arrayOf("7.0.0"), + // AGP 8.3 requires Gradle 8.4 and JDK 17. + arrayOf("8.3.0-alpha11", "8.4"), + arrayOf("7.2.0", "7.4.2"), + arrayOf("7.1.0", "7.4.2"), + arrayOf("7.0.0", "7.4.2"), ) } } diff --git a/java/dagger/hilt/android/plugin/main/src/test/kotlin/BuildCacheTest.kt b/java/dagger/hilt/android/plugin/main/src/test/kotlin/BuildCacheTest.kt index 4c34dd621..c5a67afbb 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/kotlin/BuildCacheTest.kt +++ b/java/dagger/hilt/android/plugin/main/src/test/kotlin/BuildCacheTest.kt @@ -82,8 +82,6 @@ class BuildCacheTest(private val enableAggregatingTask: Boolean) { val secondResult = secondGradleRunner.build() val cacheableTasks: List<String> = mutableListOf<String>().apply { - add(":checkDebugAarMetadata") - add(":checkDebugDuplicateClasses") add(":compileDebugJavaWithJavac") add(":compressDebugAssets") add(":desugarDebugFileDependencies") @@ -105,9 +103,6 @@ class BuildCacheTest(private val enableAggregatingTask: Boolean) { add(":mergeProjectDexDebug") add(":processDebugManifestForPackage") add(":transformDebugClassesWithAsm") - add(":validateSigningDebug") - add(":writeDebugAppMetadata") - add(":writeDebugSigningConfigVersions") } val tasksFromCache = diff --git a/java/dagger/hilt/android/plugin/main/src/test/kotlin/GradleTestRunner.kt b/java/dagger/hilt/android/plugin/main/src/test/kotlin/GradleTestRunner.kt index fb47bdb13..221dfcfd4 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/kotlin/GradleTestRunner.kt +++ b/java/dagger/hilt/android/plugin/main/src/test/kotlin/GradleTestRunner.kt @@ -156,13 +156,13 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" defaultConfig { ${ if (isAppProject) "applicationId \"plugin.test\"" else "" } minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 } compileOptions { @@ -189,7 +189,8 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) { ${hiltOptions.joinToString(separator = "\n")} } ${additionalClosures.joinToString(separator = "\n")} - """.trimIndent() + """ + .trimIndent() ) } } @@ -198,9 +199,14 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) { gradlePropertiesFile?.delete() gradlePropertiesFile = tempFolder.newFile("gradle.properties").apply { - writeText(""" + writeText( + """ android.useAndroidX=true - """.trimIndent()) + // TODO(b/296583777): See if there's a better way to fix the OOM error. + org.gradle.jvmargs=-XX:MaxMetaspaceSize=1g + """ + .trimIndent() + ) } } @@ -218,7 +224,8 @@ class GradleTestRunner(val tempFolder: TemporaryFolder) { ${activities.joinToString(separator = "\n")} </application> </manifest> - """.trimIndent() + """ + .trimIndent() ) } } diff --git a/java/dagger/hilt/android/plugin/main/src/test/kotlin/IncrementalProcessorTest.kt b/java/dagger/hilt/android/plugin/main/src/test/kotlin/IncrementalProcessorTest.kt index 1e8490f1b..4fb25a0b3 100644 --- a/java/dagger/hilt/android/plugin/main/src/test/kotlin/IncrementalProcessorTest.kt +++ b/java/dagger/hilt/android/plugin/main/src/test/kotlin/IncrementalProcessorTest.kt @@ -34,11 +34,9 @@ import org.junit.runners.Parameterized @RunWith(Parameterized::class) class IncrementalProcessorTest(private val incapMode: String) { - @get:Rule - val testProjectDir = TemporaryFolder() + @get:Rule val testProjectDir = TemporaryFolder() - @get:Rule - val expect: Expect = Expect.create() + @get:Rule val expect: Expect = Expect.create() // Original source files private lateinit var srcApp: File @@ -108,16 +106,18 @@ class IncrementalProcessorTest(private val incapMode: String) { private lateinit var unchangedFiles: Set<File> private lateinit var deletedFiles: Set<File> - private val compileTaskName = if (incapMode == ISOLATING_MODE) { - ":hiltJavaCompileDebug" - } else { - ":compileDebugJavaWithJavac" - } - private val testCompileTaskName = if (incapMode == ISOLATING_MODE) { - ":hiltJavaCompileDebugUnitTest" - } else { - ":compileDebugUnitTestJavaWithJavac" - } + private val compileTaskName = + if (incapMode == ISOLATING_MODE) { + ":hiltJavaCompileDebug" + } else { + ":compileDebugJavaWithJavac" + } + private val testCompileTaskName = + if (incapMode == ISOLATING_MODE) { + ":hiltJavaCompileDebugUnitTest" + } else { + ":compileDebugUnitTestJavaWithJavac" + } private val aggregatingTaskName = ":hiltAggregateDepsDebug" private val testAggregatingTaskName = ":hiltAggregateDepsDebugUnitTest" @@ -128,8 +128,9 @@ class IncrementalProcessorTest(private val incapMode: String) { File("src/test/data/simple-project").copyRecursively(projectRoot) // set up build file - File(projectRoot, "build.gradle").writeText( - """ + File(projectRoot, "build.gradle") + .writeText( + """ buildscript { repositories { google() @@ -146,13 +147,13 @@ class IncrementalProcessorTest(private val incapMode: String) { } android { - compileSdkVersion 32 - buildToolsVersion "32.0.0" + compileSdkVersion 33 + buildToolsVersion "33.0.0" defaultConfig { applicationId "hilt.simple" minSdkVersion 21 - targetSdkVersion 32 + targetSdkVersion 33 javaCompileOptions { annotationProcessorOptions { arguments += ["dagger.hilt.shareTestComponents" : "true"] @@ -190,32 +191,36 @@ class IncrementalProcessorTest(private val incapMode: String) { hilt { enableAggregatingTask = ${if (incapMode == ISOLATING_MODE) "true" else "false"} } - """.trimIndent() - ) + """ + .trimIndent() + ) // Compute directory paths val defaultGenSrcDir = "build/generated/ap_generated_sources/debug/out/" - fun getComponentTreeDepsGenSrcDir(variant: String) = if (incapMode == ISOLATING_MODE) { - "build/generated/hilt/component_trees/$variant/" - } else { - "build/generated/ap_generated_sources/$variant/out/" - } + fun getComponentTreeDepsGenSrcDir(variant: String) = + if (incapMode == ISOLATING_MODE) { + "build/generated/hilt/component_trees/$variant/" + } else { + "build/generated/ap_generated_sources/$variant/out/" + } val componentTreeDepsGenSrcDir = getComponentTreeDepsGenSrcDir("debug") val testComponentTreeDepsGenSrcDir = getComponentTreeDepsGenSrcDir("debugUnitTest") - fun getRootGenSrcDir(variant: String) = if (incapMode == ISOLATING_MODE) { - "build/generated/hilt/component_sources/$variant/" - } else { - "build/generated/ap_generated_sources/$variant/out/" - } + fun getRootGenSrcDir(variant: String) = + if (incapMode == ISOLATING_MODE) { + "build/generated/hilt/component_sources/$variant/" + } else { + "build/generated/ap_generated_sources/$variant/out/" + } val rootGenSrcDir = getRootGenSrcDir("debug") val testRootGenSrcDir = getRootGenSrcDir("debugUnitTest") val defaultClassesDir = "build/intermediates/javac/debug/classes" val testDefaultClassesDir = "build/intermediates/javac/debugUnitTest/classes" - fun getRootClassesDir(variant: String) = if (incapMode == ISOLATING_MODE) { - "build/intermediates/hilt/component_classes/$variant/" - } else { - "build/intermediates/javac/$variant/classes" - } + fun getRootClassesDir(variant: String) = + if (incapMode == ISOLATING_MODE) { + "build/intermediates/hilt/component_classes/$variant/" + } else { + "build/intermediates/javac/$variant/classes" + } val rootClassesDir = getRootClassesDir("debug") val testRootClassesDir = getRootClassesDir("debugUnitTest") @@ -236,59 +241,64 @@ class IncrementalProcessorTest(private val incapMode: String) { File(projectRoot, "$defaultGenSrcDir/simple/Activity1_GeneratedInjector.java") genActivityInjector2 = File(projectRoot, "$defaultGenSrcDir/simple/Activity2_GeneratedInjector.java") - genAppInjectorDeps = File( - projectRoot, - "$defaultGenSrcDir/hilt_aggregated_deps/_simple_SimpleApp_GeneratedInjector.java" - ) - genActivityInjectorDeps1 = File( - projectRoot, - "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Activity1_GeneratedInjector.java" - ) - genActivityInjectorDeps2 = File( - projectRoot, - "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Activity2_GeneratedInjector.java" - ) - genModuleDeps1 = File( - projectRoot, - "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Module1.java" - ) + genAppInjectorDeps = + File( + projectRoot, + "$defaultGenSrcDir/hilt_aggregated_deps/_simple_SimpleApp_GeneratedInjector.java" + ) + genActivityInjectorDeps1 = + File( + projectRoot, + "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Activity1_GeneratedInjector.java" + ) + genActivityInjectorDeps2 = + File( + projectRoot, + "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Activity2_GeneratedInjector.java" + ) + genModuleDeps1 = + File(projectRoot, "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Module1.java") genModuleDeps2 = File(projectRoot, "$defaultGenSrcDir/hilt_aggregated_deps/_simple_Module2.java") genComponentTreeDeps = File(projectRoot, "$componentTreeDepsGenSrcDir/simple/SimpleApp_ComponentTreeDeps.java") genHiltComponents = File(projectRoot, "$rootGenSrcDir/simple/SimpleApp_HiltComponents.java") - genDaggerHiltApplicationComponent = File( - projectRoot, - "$rootGenSrcDir/simple/DaggerSimpleApp_HiltComponents_SingletonC.java" - ) - genTest1ComponentTreeDeps = File( - projectRoot, - testComponentTreeDepsGenSrcDir + - "/dagger/hilt/android/internal/testing/root/Test1_ComponentTreeDeps.java" - ) - genTest2ComponentTreeDeps = File( - projectRoot, - testComponentTreeDepsGenSrcDir + - "/dagger/hilt/android/internal/testing/root/Test2_ComponentTreeDeps.java" - ) - genTest1HiltComponents = File( - projectRoot, - "$testRootGenSrcDir/dagger/hilt/android/internal/testing/root/Test1_HiltComponents.java" - ) - genTest2HiltComponents = File( - projectRoot, - "$testRootGenSrcDir/dagger/hilt/android/internal/testing/root/Test2_HiltComponents.java" - ) - genTest1DaggerHiltApplicationComponent = File( - projectRoot, - testRootGenSrcDir + - "/dagger/hilt/android/internal/testing/root/DaggerTest1_HiltComponents_SingletonC.java" - ) - genTest2DaggerHiltApplicationComponent = File( - projectRoot, - testRootGenSrcDir + - "/dagger/hilt/android/internal/testing/root/DaggerTest2_HiltComponents_SingletonC.java" - ) + genDaggerHiltApplicationComponent = + File(projectRoot, "$rootGenSrcDir/simple/DaggerSimpleApp_HiltComponents_SingletonC.java") + genTest1ComponentTreeDeps = + File( + projectRoot, + testComponentTreeDepsGenSrcDir + + "/dagger/hilt/android/internal/testing/root/Test1_ComponentTreeDeps.java" + ) + genTest2ComponentTreeDeps = + File( + projectRoot, + testComponentTreeDepsGenSrcDir + + "/dagger/hilt/android/internal/testing/root/Test2_ComponentTreeDeps.java" + ) + genTest1HiltComponents = + File( + projectRoot, + "$testRootGenSrcDir/dagger/hilt/android/internal/testing/root/Test1_HiltComponents.java" + ) + genTest2HiltComponents = + File( + projectRoot, + "$testRootGenSrcDir/dagger/hilt/android/internal/testing/root/Test2_HiltComponents.java" + ) + genTest1DaggerHiltApplicationComponent = + File( + projectRoot, + testRootGenSrcDir + + "/dagger/hilt/android/internal/testing/root/DaggerTest1_HiltComponents_SingletonC.java" + ) + genTest2DaggerHiltApplicationComponent = + File( + projectRoot, + testRootGenSrcDir + + "/dagger/hilt/android/internal/testing/root/DaggerTest2_HiltComponents_SingletonC.java" + ) classSrcApp = File(projectRoot, "$defaultClassesDir/simple/SimpleApp.class") classSrcActivity1 = File(projectRoot, "$defaultClassesDir/simple/Activity1.class") @@ -302,70 +312,69 @@ class IncrementalProcessorTest(private val incapMode: String) { classGenHiltActivity2 = File(projectRoot, "$defaultClassesDir/simple/Hilt_Activity2.class") classGenAppInjector = File(projectRoot, "$defaultClassesDir/simple/SimpleApp_GeneratedInjector.class") - classGenActivityInjector1 = File( - projectRoot, - "$defaultClassesDir/simple/Activity1_GeneratedInjector.class" - ) - classGenActivityInjector2 = File( - projectRoot, - "$defaultClassesDir/simple/Activity2_GeneratedInjector.class" - ) - classGenAppInjectorDeps = File( - projectRoot, - "$defaultClassesDir/hilt_aggregated_deps/_simple_SimpleApp_GeneratedInjector.class" - ) - classGenActivityInjectorDeps1 = File( - projectRoot, - "$defaultClassesDir/hilt_aggregated_deps/_simple_Activity1_GeneratedInjector.class" - ) - classGenActivityInjectorDeps2 = File( - projectRoot, - "$defaultClassesDir/hilt_aggregated_deps/_simple_Activity2_GeneratedInjector.class" - ) + classGenActivityInjector1 = + File(projectRoot, "$defaultClassesDir/simple/Activity1_GeneratedInjector.class") + classGenActivityInjector2 = + File(projectRoot, "$defaultClassesDir/simple/Activity2_GeneratedInjector.class") + classGenAppInjectorDeps = + File( + projectRoot, + "$defaultClassesDir/hilt_aggregated_deps/_simple_SimpleApp_GeneratedInjector.class" + ) + classGenActivityInjectorDeps1 = + File( + projectRoot, + "$defaultClassesDir/hilt_aggregated_deps/_simple_Activity1_GeneratedInjector.class" + ) + classGenActivityInjectorDeps2 = + File( + projectRoot, + "$defaultClassesDir/hilt_aggregated_deps/_simple_Activity2_GeneratedInjector.class" + ) classGenModuleDeps1 = File(projectRoot, "$defaultClassesDir/hilt_aggregated_deps/_simple_Module1.class") classGenModuleDeps2 = File(projectRoot, "$defaultClassesDir/hilt_aggregated_deps/_simple_Module2.class") - classGenComponentTreeDeps = File( - projectRoot, - "$rootClassesDir/simple/SimpleApp_ComponentTreeDeps.class" - ) - classGenHiltComponents = File( - projectRoot, - "$rootClassesDir/simple/SimpleApp_HiltComponents.class" - ) - classGenDaggerHiltApplicationComponent = File( - projectRoot, - "$rootClassesDir/simple/DaggerSimpleApp_HiltComponents_SingletonC.class" - ) - classGenTest1ComponentTreeDeps = File( - projectRoot, - testRootClassesDir + - "/dagger/hilt/android/internal/testing/root/Test1_ComponentTreeDeps.class" - ) - classGenTest2ComponentTreeDeps = File( - projectRoot, - testRootClassesDir + - "/dagger/hilt/android/internal/testing/root/Test2_ComponentTreeDeps.class" - ) - classGenTest1HiltComponents = File( - projectRoot, - "$testRootClassesDir/dagger/hilt/android/internal/testing/root/Test1_HiltComponents.class" - ) - classGenTest2HiltComponents = File( - projectRoot, - "$testRootClassesDir/dagger/hilt/android/internal/testing/root/Test2_HiltComponents.class" - ) - classGenTest1DaggerHiltApplicationComponent = File( - projectRoot, - testRootClassesDir + - "/dagger/hilt/android/internal/testing/root/DaggerTest1_HiltComponents_SingletonC.class" - ) - classGenTest2DaggerHiltApplicationComponent = File( - projectRoot, - testRootClassesDir + - "/dagger/hilt/android/internal/testing/root/DaggerTest2_HiltComponents_SingletonC.class" - ) + classGenComponentTreeDeps = + File(projectRoot, "$rootClassesDir/simple/SimpleApp_ComponentTreeDeps.class") + classGenHiltComponents = + File(projectRoot, "$rootClassesDir/simple/SimpleApp_HiltComponents.class") + classGenDaggerHiltApplicationComponent = + File(projectRoot, "$rootClassesDir/simple/DaggerSimpleApp_HiltComponents_SingletonC.class") + classGenTest1ComponentTreeDeps = + File( + projectRoot, + testRootClassesDir + + "/dagger/hilt/android/internal/testing/root/Test1_ComponentTreeDeps.class" + ) + classGenTest2ComponentTreeDeps = + File( + projectRoot, + testRootClassesDir + + "/dagger/hilt/android/internal/testing/root/Test2_ComponentTreeDeps.class" + ) + classGenTest1HiltComponents = + File( + projectRoot, + "$testRootClassesDir/dagger/hilt/android/internal/testing/root/Test1_HiltComponents.class" + ) + classGenTest2HiltComponents = + File( + projectRoot, + "$testRootClassesDir/dagger/hilt/android/internal/testing/root/Test2_HiltComponents.class" + ) + classGenTest1DaggerHiltApplicationComponent = + File( + projectRoot, + testRootClassesDir + + "/dagger/hilt/android/internal/testing/root/DaggerTest1_HiltComponents_SingletonC.class" + ) + classGenTest2DaggerHiltApplicationComponent = + File( + projectRoot, + testRootClassesDir + + "/dagger/hilt/android/internal/testing/root/DaggerTest2_HiltComponents_SingletonC.class" + ) } @Test @@ -428,13 +437,15 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Activity 1 source searchAndReplace( - srcActivity1, "// Insert-change", + srcActivity1, + "// Insert-change", """ @Override public void onResume() { super.onResume(); } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalBuild() @@ -442,66 +453,69 @@ class IncrementalProcessorTest(private val incapMode: String) { // Check annotation processing outputs // * Only activity 1 sources are re-generated, isolation in modules and from other activities - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task did not run, no change in deps - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) - // * Components are re-generated due to a recompilation of a dep - listOf( - genHiltApp, // Re-gen because components got re-gen - genHiltActivity1, - genActivityInjector1, - genActivityInjectorDeps1, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } else { - // * Root classes along with components are always re-generated (aggregated processor) - listOf( - genHiltApp, - genHiltActivity1, - genAppInjector, - genActivityInjector1, - genAppInjectorDeps, - genActivityInjectorDeps1, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task did not run, no change in deps + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + // * Components are re-generated due to a recompilation of a dep + listOf( + genHiltApp, // Re-gen because components got re-gen + genHiltActivity1, + genActivityInjector1, + genActivityInjectorDeps1, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } else { + // * Root classes along with components are always re-generated (aggregated processor) + listOf( + genHiltApp, + genHiltActivity1, + genAppInjector, + genActivityInjector1, + genAppInjectorDeps, + genActivityInjectorDeps1, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(componentTreeDepsFullBuild) - .isEqualTo(componentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(componentTreeDepsFullBuild) + .isEqualTo(componentTreeDepsIncrementalBuild) // Check compilation outputs // * Gen sources from activity 1 are re-compiled - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classSrcActivity1, - classGenHiltApp, - classGenHiltActivity1, - classGenActivityInjector1, - classGenActivityInjectorDeps1, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent, - ) - } else { - // * All aggregating processor gen sources are re-compiled - listOf( - classSrcActivity1, - classGenHiltApp, - classGenHiltActivity1, - classGenAppInjector, - classGenActivityInjector1, - classGenAppInjectorDeps, - classGenActivityInjectorDeps1, - classGenHiltComponents, - classGenComponentTreeDeps, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classSrcActivity1, + classGenHiltApp, + classGenHiltActivity1, + classGenActivityInjector1, + classGenActivityInjectorDeps1, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent, + ) + } else { + // * All aggregating processor gen sources are re-compiled + listOf( + classSrcActivity1, + classGenHiltApp, + classGenHiltActivity1, + classGenAppInjector, + classGenActivityInjector1, + classGenAppInjectorDeps, + classGenActivityInjectorDeps1, + classGenHiltComponents, + classGenComponentTreeDeps, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -512,76 +526,82 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Activity 1 source searchAndReplace( - srcActivity1, "// Insert-change", + srcActivity1, + "// Insert-change", """ private void foo() { } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalBuild() - val expectedOutcome = if (incapMode == ISOLATING_MODE) { - // In isolating mode, changes that do not affect ABI will not cause re-compilation. - TaskOutcome.UP_TO_DATE - } else { - TaskOutcome.SUCCESS - } + val expectedOutcome = + if (incapMode == ISOLATING_MODE) { + // In isolating mode, changes that do not affect ABI will not cause re-compilation. + TaskOutcome.UP_TO_DATE + } else { + TaskOutcome.SUCCESS + } expect.that(result.task(compileTaskName)!!.outcome).isEqualTo(expectedOutcome) // Check annotation processing outputs // * Only activity 1 sources are re-generated, isolation in modules and from other activities - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task did not run, no change in deps - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) - listOf( - genHiltActivity1, - genActivityInjector1, - genActivityInjectorDeps1, - ) - } else { - // * Root classes along with components are always re-generated (aggregated processor) - listOf( - genHiltApp, - genHiltActivity1, - genAppInjector, - genActivityInjector1, - genAppInjectorDeps, - genActivityInjectorDeps1, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task did not run, no change in deps + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + listOf( + genHiltActivity1, + genActivityInjector1, + genActivityInjectorDeps1, + ) + } else { + // * Root classes along with components are always re-generated (aggregated processor) + listOf( + genHiltApp, + genHiltActivity1, + genAppInjector, + genActivityInjector1, + genAppInjectorDeps, + genActivityInjectorDeps1, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(componentTreeDepsFullBuild) - .isEqualTo(componentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(componentTreeDepsFullBuild) + .isEqualTo(componentTreeDepsIncrementalBuild) // Check compilation outputs // * Gen sources from activity 1 are re-compiled - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classSrcActivity1, - classGenHiltActivity1, - classGenActivityInjector1, - classGenActivityInjectorDeps1 - ) - } else { - // * All aggregating processor gen sources are re-compiled - listOf( - classSrcActivity1, - classGenHiltApp, - classGenHiltActivity1, - classGenAppInjector, - classGenActivityInjector1, - classGenAppInjectorDeps, - classGenActivityInjectorDeps1, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classSrcActivity1, + classGenHiltActivity1, + classGenActivityInjector1, + classGenActivityInjectorDeps1 + ) + } else { + // * All aggregating processor gen sources are re-compiled + listOf( + classSrcActivity1, + classGenHiltApp, + classGenHiltActivity1, + classGenAppInjector, + classGenActivityInjector1, + classGenAppInjectorDeps, + classGenActivityInjectorDeps1, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -592,13 +612,15 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Module 1 source searchAndReplace( - srcModule1, "// Insert-change", + srcModule1, + "// Insert-change", """ @Provides static double provideDouble() { return 10.10; } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalBuild() @@ -606,58 +628,61 @@ class IncrementalProcessorTest(private val incapMode: String) { // Check annotation processing outputs // * Only module 1 sources are re-generated, isolation from other modules - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task did not run, no change in deps - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) - // * Components are re-generated due to a recompilation of a dep - listOf( - genHiltApp, // Re-generated because components got re-generated - genModuleDeps1, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } else { - // * Root classes along with components are always re-generated (aggregated processor) - listOf( - genHiltApp, - genAppInjector, - genAppInjectorDeps, - genModuleDeps1, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task did not run, no change in deps + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + // * Components are re-generated due to a recompilation of a dep + listOf( + genHiltApp, // Re-generated because components got re-generated + genModuleDeps1, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } else { + // * Root classes along with components are always re-generated (aggregated processor) + listOf( + genHiltApp, + genAppInjector, + genAppInjectorDeps, + genModuleDeps1, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(componentTreeDepsFullBuild) - .isEqualTo(componentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(componentTreeDepsFullBuild) + .isEqualTo(componentTreeDepsIncrementalBuild) // Check compilation outputs // * Gen sources from module 1 are re-compiled - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classSrcModule1, - classGenHiltApp, - classGenModuleDeps1, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } else { - // * All aggregating processor gen sources are re-compiled - listOf( - classSrcModule1, - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenModuleDeps1, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classSrcModule1, + classGenHiltApp, + classGenModuleDeps1, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } else { + // * All aggregating processor gen sources are re-compiled + listOf( + classSrcModule1, + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenModuleDeps1, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -668,13 +693,15 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Application source searchAndReplace( - srcApp, "// Insert-change", + srcApp, + "// Insert-change", """ @Override public void onCreate() { super.onCreate(); } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalBuild() @@ -682,57 +709,60 @@ class IncrementalProcessorTest(private val incapMode: String) { // Check annotation processing outputs // * No modules or activities (or any other non-root) classes should be generated - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task did not run, no change in deps - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) - // * Components are re-generated due to a recompilation of a dep - listOf( - genHiltApp, // Re-generated because components got re-generated - genAppInjector, - genAppInjectorDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } else { - // * Root classes along with components are always re-generated (aggregated processor) - listOf( - genHiltApp, - genAppInjector, - genAppInjectorDeps, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task did not run, no change in deps + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + // * Components are re-generated due to a recompilation of a dep + listOf( + genHiltApp, // Re-generated because components got re-generated + genAppInjector, + genAppInjectorDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } else { + // * Root classes along with components are always re-generated (aggregated processor) + listOf( + genHiltApp, + genAppInjector, + genAppInjectorDeps, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val componentTreeDepsIncrementalBuild = genComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(componentTreeDepsFullBuild) - .isEqualTo(componentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(componentTreeDepsFullBuild) + .isEqualTo(componentTreeDepsIncrementalBuild) // Check compilation outputs - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classSrcApp, - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } else { - // * All aggregating processor gen sources are re-compiled - listOf( - classSrcApp, - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classSrcApp, + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } else { + // * All aggregating processor gen sources are re-compiled + listOf( + classSrcApp, + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -749,33 +779,28 @@ class IncrementalProcessorTest(private val incapMode: String) { // * All related gen classes from activity 2 should be deleted // * Unrelated activities and modules are in isolation and should be unchanged // * Root classes along with components are always re-generated (aggregated processor) - assertDeletedFiles( - listOf( - genHiltActivity2, - genActivityInjector2, - genActivityInjectorDeps2 - ) - ) - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task ran due to a change in dep - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.SUCCESS) - // * Components are re-generated since there was a change in dep - listOf( - genHiltApp, // Re-generated because components got re-generated - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } else { - listOf( - genHiltApp, - genAppInjector, - genAppInjectorDeps, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + assertDeletedFiles(listOf(genHiltActivity2, genActivityInjector2, genActivityInjectorDeps2)) + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task ran due to a change in dep + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.SUCCESS) + // * Components are re-generated since there was a change in dep + listOf( + genHiltApp, // Re-generated because components got re-generated + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } else { + listOf( + genHiltApp, + genAppInjector, + genAppInjectorDeps, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) // Check compilation outputs @@ -789,23 +814,24 @@ class IncrementalProcessorTest(private val incapMode: String) { classGenActivityInjectorDeps2 ) ) - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classGenHiltApp, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } else { - listOf( - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classGenHiltApp, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } else { + listOf( + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -822,58 +848,53 @@ class IncrementalProcessorTest(private val incapMode: String) { // * All related gen classes from module 2 should be deleted // * Unrelated activities and modules are in isolation and should be unchanged - assertDeletedFiles( - listOf(genModuleDeps2) - ) - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task ran due to a change in dep - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.SUCCESS) - // * Components are re-generated since there was a change in dep - listOf( - genHiltApp, // Re-generated because components got re-generated - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } else { - // * Root classes along with components are always re-generated (aggregated processor) - listOf( - genHiltApp, - genAppInjector, - genAppInjectorDeps, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + assertDeletedFiles(listOf(genModuleDeps2)) + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task ran due to a change in dep + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.SUCCESS) + // * Components are re-generated since there was a change in dep + listOf( + genHiltApp, // Re-generated because components got re-generated + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } else { + // * Root classes along with components are always re-generated (aggregated processor) + listOf( + genHiltApp, + genAppInjector, + genAppInjectorDeps, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) // Check compilation outputs // * All compiled classes from module 2 should be deleted // * Unrelated activities and modules are in isolation and should be unchanged - assertDeletedFiles( - listOf( - classSrcModule2, - classGenModuleDeps2 - ) - ) - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classGenHiltApp, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } else { - listOf( - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + assertDeletedFiles(listOf(classSrcModule2, classGenModuleDeps2)) + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classGenHiltApp, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } else { + listOf( + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -887,48 +908,52 @@ class IncrementalProcessorTest(private val incapMode: String) { package simple; public class Foo { } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalBuild() - val expectedOutcome = if (incapMode == ISOLATING_MODE) { - // In isolating mode, component compile task does not re-compile. - TaskOutcome.UP_TO_DATE - } else { - TaskOutcome.SUCCESS - } + val expectedOutcome = + if (incapMode == ISOLATING_MODE) { + // In isolating mode, component compile task does not re-compile. + TaskOutcome.UP_TO_DATE + } else { + TaskOutcome.SUCCESS + } expect.that(result.task(compileTaskName)!!.outcome).isEqualTo(expectedOutcome) - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - // * Aggregating task did not run, no change in deps - expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) - // * Non-DI related source causes no files to be generated - emptyList() - } else { - // * Root classes are always re-generated (aggregated processor) - listOf( - genHiltApp, - genAppInjector, - genAppInjectorDeps, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + // * Aggregating task did not run, no change in deps + expect.that(result.task(aggregatingTaskName)!!.outcome).isEqualTo(TaskOutcome.UP_TO_DATE) + // * Non-DI related source causes no files to be generated + emptyList() + } else { + // * Root classes are always re-generated (aggregated processor) + listOf( + genHiltApp, + genAppInjector, + genAppInjectorDeps, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - emptyList() - } else { - listOf( - classGenHiltApp, - classGenAppInjector, - classGenAppInjectorDeps, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent - ) - } + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + emptyList() + } else { + listOf( + classGenHiltApp, + classGenAppInjector, + classGenAppInjectorDeps, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -970,11 +995,13 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Test 1 source searchAndReplace( - srcTest1, "// Insert-change", + srcTest1, + "// Insert-change", """ @Test public void newTest() { } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalTestBuild() @@ -983,49 +1010,53 @@ class IncrementalProcessorTest(private val incapMode: String) { // Check annotation processing outputs // * Unrelated test components should be unchanged - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - listOf( - genTest1HiltComponents, - genTest1DaggerHiltApplicationComponent, - ) - } else { - listOf( - genTest1ComponentTreeDeps, - genTest2ComponentTreeDeps, - genTest1HiltComponents, - genTest2HiltComponents, - genTest1DaggerHiltApplicationComponent, - genTest2DaggerHiltApplicationComponent, - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + genTest1HiltComponents, + genTest1DaggerHiltApplicationComponent, + ) + } else { + listOf( + genTest1ComponentTreeDeps, + genTest2ComponentTreeDeps, + genTest1HiltComponents, + genTest2HiltComponents, + genTest1DaggerHiltApplicationComponent, + genTest2DaggerHiltApplicationComponent, + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val test1ComponentTreeDepsIncrementalBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8) val test2ComponentTreeDepsIncrementalBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(test1ComponentTreeDepsFullBuild) - .isEqualTo(test1ComponentTreeDepsIncrementalBuild) - expect.withMessage("Full build") - .that(test2ComponentTreeDepsFullBuild) - .isEqualTo(test2ComponentTreeDepsIncrementalBuild) - - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf( - classSrcTest1, - classGenTest1HiltComponents, - classGenTest1DaggerHiltApplicationComponent, - ) - } else { - listOf( - classSrcTest1, - classGenTest1ComponentTreeDeps, - classGenTest2ComponentTreeDeps, - classGenTest1HiltComponents, - classGenTest2HiltComponents, - classGenTest1DaggerHiltApplicationComponent, - classGenTest2DaggerHiltApplicationComponent, - ) - } + expect + .withMessage("Full build") + .that(test1ComponentTreeDepsFullBuild) + .isEqualTo(test1ComponentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(test2ComponentTreeDepsFullBuild) + .isEqualTo(test2ComponentTreeDepsIncrementalBuild) + + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf( + classSrcTest1, + classGenTest1HiltComponents, + classGenTest1DaggerHiltApplicationComponent, + ) + } else { + listOf( + classSrcTest1, + classGenTest1ComponentTreeDeps, + classGenTest2ComponentTreeDeps, + classGenTest1HiltComponents, + classGenTest2HiltComponents, + classGenTest1DaggerHiltApplicationComponent, + classGenTest2DaggerHiltApplicationComponent, + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -1037,60 +1068,67 @@ class IncrementalProcessorTest(private val incapMode: String) { // Change Test 1 source searchAndReplace( - srcTest1, "// Insert-change", + srcTest1, + "// Insert-change", """ private void newMethod() { } - """.trimIndent() + """ + .trimIndent() ) val result = runIncrementalTestBuild() - val expectedOutcome = if (incapMode == ISOLATING_MODE) { - // In isolating mode, changes that do not affect ABI will not cause re-compilation. - TaskOutcome.UP_TO_DATE - } else { - TaskOutcome.SUCCESS - } + val expectedOutcome = + if (incapMode == ISOLATING_MODE) { + // In isolating mode, changes that do not affect ABI will not cause re-compilation. + TaskOutcome.UP_TO_DATE + } else { + TaskOutcome.SUCCESS + } expect.that(result.task(testCompileTaskName)!!.outcome).isEqualTo(expectedOutcome) // Check annotation processing outputs // * Unrelated test components should be unchanged - val regeneratedSourceFiles = if (incapMode == ISOLATING_MODE) { - emptyList() - } else { - listOf( - genTest1ComponentTreeDeps, - genTest2ComponentTreeDeps, - genTest1HiltComponents, - genTest2HiltComponents, - genTest1DaggerHiltApplicationComponent, - genTest2DaggerHiltApplicationComponent, - ) - } + val regeneratedSourceFiles = + if (incapMode == ISOLATING_MODE) { + emptyList() + } else { + listOf( + genTest1ComponentTreeDeps, + genTest2ComponentTreeDeps, + genTest1HiltComponents, + genTest2HiltComponents, + genTest1DaggerHiltApplicationComponent, + genTest2DaggerHiltApplicationComponent, + ) + } assertChangedFiles(FileType.JAVA, regeneratedSourceFiles) val test1ComponentTreeDepsIncrementalBuild = genTest1ComponentTreeDeps.readText(Charsets.UTF_8) val test2ComponentTreeDepsIncrementalBuild = genTest2ComponentTreeDeps.readText(Charsets.UTF_8) - expect.withMessage("Full build") - .that(test1ComponentTreeDepsFullBuild) - .isEqualTo(test1ComponentTreeDepsIncrementalBuild) - expect.withMessage("Full build") - .that(test2ComponentTreeDepsFullBuild) - .isEqualTo(test2ComponentTreeDepsIncrementalBuild) - - val recompiledClassFiles = if (incapMode == ISOLATING_MODE) { - listOf(classSrcTest1) - } else { - listOf( - classSrcTest1, - classGenTest1ComponentTreeDeps, - classGenTest2ComponentTreeDeps, - classGenTest1HiltComponents, - classGenTest2HiltComponents, - classGenTest1DaggerHiltApplicationComponent, - classGenTest2DaggerHiltApplicationComponent, - ) - } + expect + .withMessage("Full build") + .that(test1ComponentTreeDepsFullBuild) + .isEqualTo(test1ComponentTreeDepsIncrementalBuild) + expect + .withMessage("Full build") + .that(test2ComponentTreeDepsFullBuild) + .isEqualTo(test2ComponentTreeDepsIncrementalBuild) + + val recompiledClassFiles = + if (incapMode == ISOLATING_MODE) { + listOf(classSrcTest1) + } else { + listOf( + classSrcTest1, + classGenTest1ComponentTreeDeps, + classGenTest2ComponentTreeDeps, + classGenTest1HiltComponents, + classGenTest2HiltComponents, + classGenTest1DaggerHiltApplicationComponent, + classGenTest2DaggerHiltApplicationComponent, + ) + } assertChangedFiles(FileType.CLASS, recompiledClassFiles) } @@ -1129,83 +1167,93 @@ class IncrementalProcessorTest(private val incapMode: String) { } private fun recordTimestamps() { - val files = listOf( - genHiltApp, - genHiltActivity1, - genHiltActivity2, - genAppInjector, - genActivityInjector1, - genActivityInjector2, - genAppInjectorDeps, - genActivityInjectorDeps1, - genActivityInjectorDeps2, - genModuleDeps1, - genModuleDeps2, - genComponentTreeDeps, - genHiltComponents, - genDaggerHiltApplicationComponent, - genTest1ComponentTreeDeps, - genTest2ComponentTreeDeps, - genTest1HiltComponents, - genTest2HiltComponents, - genTest1DaggerHiltApplicationComponent, - genTest2DaggerHiltApplicationComponent, - classSrcApp, - classSrcActivity1, - classSrcActivity2, - classSrcModule1, - classSrcModule2, - classSrcTest1, - classSrcTest2, - classGenHiltApp, - classGenHiltActivity1, - classGenHiltActivity2, - classGenAppInjector, - classGenActivityInjector1, - classGenActivityInjector2, - classGenAppInjectorDeps, - classGenActivityInjectorDeps1, - classGenActivityInjectorDeps2, - classGenModuleDeps1, - classGenModuleDeps2, - classGenComponentTreeDeps, - classGenHiltComponents, - classGenDaggerHiltApplicationComponent, - classGenTest1ComponentTreeDeps, - classGenTest2ComponentTreeDeps, - classGenTest1HiltComponents, - classGenTest2HiltComponents, - classGenTest1DaggerHiltApplicationComponent, - classGenTest2DaggerHiltApplicationComponent, - ) + val files = + listOf( + genHiltApp, + genHiltActivity1, + genHiltActivity2, + genAppInjector, + genActivityInjector1, + genActivityInjector2, + genAppInjectorDeps, + genActivityInjectorDeps1, + genActivityInjectorDeps2, + genModuleDeps1, + genModuleDeps2, + genComponentTreeDeps, + genHiltComponents, + genDaggerHiltApplicationComponent, + genTest1ComponentTreeDeps, + genTest2ComponentTreeDeps, + genTest1HiltComponents, + genTest2HiltComponents, + genTest1DaggerHiltApplicationComponent, + genTest2DaggerHiltApplicationComponent, + classSrcApp, + classSrcActivity1, + classSrcActivity2, + classSrcModule1, + classSrcModule2, + classSrcTest1, + classSrcTest2, + classGenHiltApp, + classGenHiltActivity1, + classGenHiltActivity2, + classGenAppInjector, + classGenActivityInjector1, + classGenActivityInjector2, + classGenAppInjectorDeps, + classGenActivityInjectorDeps1, + classGenActivityInjectorDeps2, + classGenModuleDeps1, + classGenModuleDeps2, + classGenComponentTreeDeps, + classGenHiltComponents, + classGenDaggerHiltApplicationComponent, + classGenTest1ComponentTreeDeps, + classGenTest2ComponentTreeDeps, + classGenTest1HiltComponents, + classGenTest2HiltComponents, + classGenTest1DaggerHiltApplicationComponent, + classGenTest2DaggerHiltApplicationComponent, + ) - fileToTimestampMap = mutableMapOf<File, Long>().apply { - for (file in files) { - this[file] = file.lastModified() + fileToTimestampMap = + mutableMapOf<File, Long>().apply { + for (file in files) { + this[file] = file.lastModified() + } } - } } private fun recordFileChanges() { - changedFiles = fileToTimestampMap.filter { (file, previousTimestamp) -> - file.exists() && file.lastModified() != previousTimestamp - }.keys + changedFiles = + fileToTimestampMap + .filter { (file, previousTimestamp) -> + file.exists() && file.lastModified() != previousTimestamp + } + .keys - unchangedFiles = fileToTimestampMap.filter { (file, previousTimestamp) -> - file.exists() && file.lastModified() == previousTimestamp - }.keys + unchangedFiles = + fileToTimestampMap + .filter { (file, previousTimestamp) -> + file.exists() && file.lastModified() == previousTimestamp + } + .keys deletedFiles = fileToTimestampMap.filter { (file, _) -> !file.exists() }.keys } private fun assertFilesExist(files: Collection<File>) { - expect.withMessage("Existing files") + expect + .withMessage("Existing files") .that(files.filter { it.exists() }) .containsExactlyElementsIn(files) } private fun assertChangedFiles(type: FileType, files: Collection<File>) { - expect.withMessage("Changed files") + expect + .withMessage("Changed files") .that(changedFiles.filter { it.name.endsWith(type.extension) }) .containsExactlyElementsIn(files) } @@ -1227,10 +1275,7 @@ class IncrementalProcessorTest(private val incapMode: String) { @JvmStatic @Parameterized.Parameters(name = "{0}") - fun parameters() = listOf( - ISOLATING_MODE, - AGGREGATING_MODE - ) + fun parameters() = listOf(ISOLATING_MODE, AGGREGATING_MODE) private const val ISOLATING_MODE = "isolating" private const val AGGREGATING_MODE = "aggregating" diff --git a/java/dagger/hilt/android/plugin/settings.gradle b/java/dagger/hilt/android/plugin/settings.gradle index 55724bf48..778bf22e4 100644 --- a/java/dagger/hilt/android/plugin/settings.gradle +++ b/java/dagger/hilt/android/plugin/settings.gradle @@ -21,3 +21,4 @@ include ':agp-wrapper-impl' include ':agp-wrapper-7-0' include ':agp-wrapper-7-1' include ':agp-wrapper-7-2' + |