@@ -22,20 +22,18 @@ import org.junit.Before
22
22
import org.junit.Rule
23
23
import org.junit.Test
24
24
import org.junit.rules.TemporaryFolder
25
+ import org.junit.runner.RunWith
26
+ import org.junit.runners.Parameterized
25
27
26
28
// Test that verifies the hilt class transform does not break the Gradle's remote build cache.
27
- class BuildCacheTest {
28
- @get:Rule
29
- val gradleHomeFolder = TemporaryFolder ()
30
-
31
- @get:Rule
32
- val firstProjectDir = TemporaryFolder ()
29
+ @RunWith(Parameterized ::class )
30
+ class BuildCacheTest (private val enableAggregatingTask : Boolean ) {
31
+ @get:Rule val gradleHomeFolder = TemporaryFolder ()
33
32
33
+ @get:Rule val firstProjectDir = TemporaryFolder ()
34
34
lateinit var firstGradleRunner: GradleTestRunner
35
35
36
- @get:Rule
37
- val secondProjectDir = TemporaryFolder ()
38
-
36
+ @get:Rule val secondProjectDir = TemporaryFolder ()
39
37
lateinit var secondGradleRunner: GradleTestRunner
40
38
41
39
private val testId = UUID .randomUUID().toString()
@@ -57,7 +55,7 @@ class BuildCacheTest {
57
55
gradleRunner.addSrc(
58
56
srcPath = " minimal/MyApp.java" ,
59
57
srcContent =
60
- """
58
+ """
61
59
package minimal;
62
60
63
61
import android.app.Application;
@@ -71,6 +69,7 @@ class BuildCacheTest {
71
69
""" .trimIndent()
72
70
)
73
71
gradleRunner.setAppClassName(" .MyApp" )
72
+ gradleRunner.addHiltOption(" enableAggregatingTask = $enableAggregatingTask " )
74
73
return gradleRunner
75
74
}
76
75
@@ -81,32 +80,44 @@ class BuildCacheTest {
81
80
assertEquals(firstResult.getTask(" :transformDebugClassesWithAsm" ).outcome, SUCCESS )
82
81
83
82
val secondResult = secondGradleRunner.build()
84
- val cacheableTasks = listOf (
85
- " :checkDebugAarMetadata" ,
86
- " :checkDebugDuplicateClasses" ,
87
- " :compileDebugJavaWithJavac" ,
88
- " :compressDebugAssets" ,
89
- " :extractDeepLinksDebug" ,
90
- " :generateDebugBuildConfig" ,
91
- " :generateDebugResValues" ,
92
- " :javaPreCompileDebug" ,
93
- " :mergeDebugAssets" ,
94
- " :mergeDebugJavaResource" ,
95
- " :mergeDebugJniLibFolders" ,
96
- " :mergeDebugNativeLibs" ,
97
- " :mergeDebugShaders" ,
98
- " :mergeExtDexDebug" ,
99
- " :mergeLibDexDebug" ,
100
- " :mergeProjectDexDebug" ,
101
- " :processDebugManifestForPackage" ,
102
- " :transformDebugClassesWithAsm" ,
103
- " :validateSigningDebug" ,
104
- " :writeDebugAppMetadata" ,
105
- " :writeDebugSigningConfigVersions" ,
106
- )
83
+ val cacheableTasks: List <String > = mutableListOf<String >().apply {
84
+ add(" :checkDebugAarMetadata" )
85
+ add(" :checkDebugDuplicateClasses" )
86
+ add(" :compileDebugJavaWithJavac" )
87
+ add(" :compressDebugAssets" )
88
+ add(" :extractDeepLinksDebug" )
89
+ add(" :generateDebugBuildConfig" )
90
+ add(" :generateDebugResValues" )
91
+ // When aggregating task is enabled, the plugin adds two more tasks that should be
92
+ // cacheable.
93
+ if (enableAggregatingTask) {
94
+ add(" :hiltAggregateDepsDebug" )
95
+ add(" :hiltJavaCompileDebug" )
96
+ }
97
+ add(" :javaPreCompileDebug" )
98
+ add(" :mergeDebugAssets" )
99
+ add(" :mergeDebugJavaResource" )
100
+ add(" :mergeDebugJniLibFolders" )
101
+ add(" :mergeDebugNativeLibs" )
102
+ add(" :mergeDebugShaders" )
103
+ add(" :mergeExtDexDebug" )
104
+ add(" :mergeLibDexDebug" )
105
+ add(" :mergeProjectDexDebug" )
106
+ add(" :processDebugManifestForPackage" )
107
+ add(" :transformDebugClassesWithAsm" )
108
+ add(" :validateSigningDebug" )
109
+ add(" :writeDebugAppMetadata" )
110
+ add(" :writeDebugSigningConfigVersions" )
111
+ }
107
112
108
113
val tasksFromCache =
109
114
secondResult.tasks.filter { it.outcome == FROM_CACHE }.map { it.path }.sorted()
110
115
assertEquals(cacheableTasks, tasksFromCache)
111
116
}
117
+
118
+ companion object {
119
+ @JvmStatic
120
+ @Parameterized.Parameters (name = " enableAggregatingTask = {0}" )
121
+ fun parameters () = listOf (false , true )
122
+ }
112
123
}
0 commit comments