Skip to content

Commit 7876626

Browse files
authored
Merge pull request #198 from gradle/no/disable-bundle-caching
Disable caching of BundleLibraryClassesJar task.
2 parents 3594e5d + b9f94c9 commit 7876626

File tree

6 files changed

+83
-16
lines changed

6 files changed

+83
-16
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,6 @@ room {
125125
* There can only be a single schema export directory for the project - you cannot configure variant-specific export
126126
directories. Schemas exported from different variants will be merged in the directory specified in the "room" extension.
127127

128-
### MergeNativeLibs, StripDebugSymbols, MergeJavaResources, and MergeSourceSetFolders Workarounds
128+
### MergeNativeLibs, StripDebugSymbols, MergeJavaResources, MergeSourceSetFolders, and BundleLibraryClassesJar Workarounds
129129

130-
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, `MergeJavaResources`, and `MergeSourceSetFolders` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.
130+
It has been observed that caching the `MergeNativeLibsTask`, `StripDebugSymbols`, `MergeJavaResources`, `MergeSourceSetFolders`, and `BundleLibraryClassesJar` tasks rarely provide any significant positive avoidance savings. In fact, they frequently provide negative savings, especially when fetched from a remote cache node. As such, these workarounds actually disable caching for these tasks.

src/main/groovy/org/gradle/android/AndroidCacheFixPlugin.groovy

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package org.gradle.android
22

33
import com.google.common.collect.ImmutableList
44
import groovy.transform.CompileStatic
5+
import org.gradle.android.workarounds.BundleLibraryClassesWorkaround
6+
import org.gradle.android.workarounds.BundleLibraryClassesWorkaround_4_2
57
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_4_0
68
import org.gradle.android.workarounds.CompileLibraryResourcesWorkaround_7_0
79
import org.gradle.android.workarounds.CompilerArgsProcessor
@@ -43,7 +45,9 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
4345
new CompileLibraryResourcesWorkaround_4_2(),
4446
new CompileLibraryResourcesWorkaround_7_0(),
4547
new MergeResourcesWorkaround(),
46-
new StripDebugSymbolsWorkaround()
48+
new StripDebugSymbolsWorkaround(),
49+
new BundleLibraryClassesWorkaround(),
50+
new BundleLibraryClassesWorkaround_4_2()
4751
)
4852
} else {
4953
return Collections.emptyList()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.gradle.android.workarounds
2+
3+
import com.android.build.gradle.internal.tasks.BundleLibraryClasses
4+
import org.gradle.android.AndroidIssue
5+
import org.gradle.api.Project
6+
7+
/**
8+
* Disables caching of the BundleLibraryClasses task which is mostly disk bound and unlikely to provide positive
9+
* performance benefits.
10+
*/
11+
@AndroidIssue(introducedIn = "3.5.0", fixedIn = ["4.1.0-alpha01"], link = "https://issuetracker.google.com/issues/199763362")
12+
class BundleLibraryClassesWorkaround implements Workaround {
13+
private static final String CACHING_ENABLED_PROPERTY = "org.gradle.android.cache-fix.BundleLibraryClasses.caching.enabled"
14+
15+
@Override
16+
void apply(WorkaroundContext context) {
17+
context.project.tasks.withType(BundleLibraryClasses).configureEach {
18+
outputs.doNotCacheIf("Caching BundleLibraryClasses is unlikely to provide positive performance results.", {true })
19+
}
20+
}
21+
22+
@Override
23+
boolean canBeApplied(Project project) {
24+
return !SystemPropertiesCompat.getBoolean(CACHING_ENABLED_PROPERTY, project)
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.gradle.android.workarounds
2+
3+
import org.gradle.android.AndroidIssue
4+
import org.gradle.api.Project
5+
6+
/**
7+
* Disables caching of the BundleLibraryClassesJar and BundleLibraryClassesDir tasks which are mostly disk bound and
8+
* unlikely to provide positive performance benefits.
9+
*/
10+
@AndroidIssue(introducedIn = "4.1.0", fixedIn = [], link = "https://issuetracker.google.com/issues/199763362")
11+
class BundleLibraryClassesWorkaround_4_2 implements Workaround {
12+
private static final String CACHING_ENABLED_PROPERTY = "org.gradle.android.cache-fix.BundleLibraryClasses.caching.enabled"
13+
14+
static Class<?> getJarTaskClass() {
15+
return Class.forName('com.android.build.gradle.internal.tasks.BundleLibraryClassesJar')
16+
}
17+
18+
static Class<?> getDirTaskClass() {
19+
return Class.forName('com.android.build.gradle.internal.tasks.BundleLibraryClassesDir')
20+
}
21+
22+
23+
@Override
24+
void apply(WorkaroundContext context) {
25+
context.project.tasks.withType(jarTaskClass).configureEach {
26+
outputs.doNotCacheIf("Caching BundleLibraryClassesJar is unlikely to provide positive performance results.", {true })
27+
}
28+
context.project.tasks.withType(dirTaskClass).configureEach {
29+
outputs.doNotCacheIf("Caching BundleLibraryClassesDir is unlikely to provide positive performance results.", {true })
30+
}
31+
}
32+
33+
@Override
34+
boolean canBeApplied(Project project) {
35+
return !SystemPropertiesCompat.getBoolean(CACHING_ENABLED_PROPERTY, project)
36+
}
37+
}

src/test/groovy/org/gradle/android/CrossVersionOutcomeAndRelocationTest.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
483483
builder.expect(':library:mergeDebugGeneratedProguardFiles', FROM_CACHE)
484484
builder.expect(':library:mergeReleaseConsumerProguardFiles', FROM_CACHE)
485485
builder.expect(':library:mergeReleaseGeneratedProguardFiles', FROM_CACHE)
486-
builder.expect(':library:bundleLibCompileToJarDebug', FROM_CACHE)
486+
builder.expect(':library:bundleLibCompileToJarDebug', SUCCESS)
487487
builder.expect(':library:bundleLibResDebug', NO_SOURCE)
488488
builder.expect(':library:bundleLibResRelease', NO_SOURCE)
489-
builder.expect(':library:bundleLibCompileToJarRelease', FROM_CACHE)
489+
builder.expect(':library:bundleLibCompileToJarRelease', SUCCESS)
490490
builder.expect(':library:stripDebugDebugSymbols', NO_SOURCE)
491491
builder.expect(':library:stripReleaseDebugSymbols', NO_SOURCE)
492492
builder.expect(':app:collectReleaseDependencies', SUCCESS)
493493
builder.expect(':app:sdkReleaseDependencyData', SUCCESS)
494494
}
495495

496496
static void android40xTo41xExpectation(ExpectedOutcomeBuilder builder) {
497-
builder.expect(':library:bundleLibRuntimeToJarDebug', FROM_CACHE)
498-
builder.expect(':library:bundleLibRuntimeToJarRelease', FROM_CACHE)
497+
builder.expect(':library:bundleLibRuntimeToJarDebug', SUCCESS)
498+
builder.expect(':library:bundleLibRuntimeToJarRelease', SUCCESS)
499499
}
500500

501501
static void android41xOrHigherExpectations(ExpectedOutcomeBuilder builder) {
@@ -540,8 +540,8 @@ class CrossVersionOutcomeAndRelocationTest extends AbstractTest {
540540

541541
static void android42xOrHigherExpectations(ExpectedOutcomeBuilder builder) {
542542
// Renamed from ToJar to ToDir
543-
builder.expect(':library:bundleLibRuntimeToDirDebug', FROM_CACHE)
544-
builder.expect(':library:bundleLibRuntimeToDirRelease', FROM_CACHE)
543+
builder.expect(':library:bundleLibRuntimeToDirDebug', SUCCESS)
544+
builder.expect(':library:bundleLibRuntimeToDirRelease', SUCCESS)
545545
builder.expect(':app:optimizeReleaseResources', FROM_CACHE)
546546
builder.expect(':app:mergeReleaseNativeDebugMetadata', NO_SOURCE)
547547
builder.expect(':app:writeDebugAppMetadata', FROM_CACHE)

src/test/groovy/org/gradle/android/WorkaroundTest.groovy

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class WorkaroundTest extends Specification {
1212
workarounds.collect { it.class.simpleName.replaceAll(/Workaround/, "") }.sort() == expectedWorkarounds.sort()
1313
where:
1414
androidVersion | expectedWorkarounds
15-
"7.1.0-alpha11" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16-
"7.0.2" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
17-
"4.2.2" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
18-
"4.1.3" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19-
"4.0.2" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
20-
"3.6.4" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
21-
"3.5.4" | ['MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
15+
"7.1.0-alpha11" | ['BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
16+
"7.0.2" | ['BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_7_0']
17+
"4.2.2" | ['BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_2', 'MergeResources']
18+
"4.1.3" | ['BundleLibraryClasses_4_2', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
19+
"4.0.2" | ['BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs', 'CompileLibraryResources_4_0', 'MergeResources']
20+
"3.6.4" | ['BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
21+
"3.5.4" | ['BundleLibraryClasses', 'MergeSourceSetFolders', 'MergeJavaResources', 'RoomSchemaLocation', 'StripDebugSymbols', 'MergeNativeLibs']
2222
}
2323
}

0 commit comments

Comments
 (0)