Skip to content

Commit 39ca807

Browse files
committed
Handle warnings for all supported versions of Gradle
1 parent b9c9b38 commit 39ca807

File tree

3 files changed

+24
-11
lines changed

3 files changed

+24
-11
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import org.gradle.android.workarounds.Workaround
1616
import org.gradle.android.workarounds.WorkaroundContext
1717
import org.gradle.api.Plugin
1818
import org.gradle.api.Project
19-
import org.gradle.api.services.BuildService
20-
import org.gradle.api.services.BuildServiceParameters
19+
import org.gradle.util.GradleVersion
2120
import org.gradle.util.VersionNumber
2221
import org.slf4j.Logger
2322
import org.slf4j.LoggerFactory
@@ -82,7 +81,13 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
8281
appliedWorkarounds += workaround.getClass().simpleName - "Workaround"
8382
}
8483

85-
project.gradle.sharedServices.registerIfAbsent("warnings", WarningsService.class) { }.get()
84+
if (GradleVersion.current() >= GradleVersion.version('6.1')) {
85+
project.gradle.sharedServices.registerIfAbsent("warnings", WarningsService.class) {}.get()
86+
} else {
87+
project.gradle.buildFinished {
88+
Warnings.resetAll()
89+
}
90+
}
8691
}
8792

8893
static List<Workaround> getWorkaroundsToApply(
@@ -115,11 +120,4 @@ class AndroidCacheFixPlugin implements Plugin<Project> {
115120
}
116121
workaroundsBuilder.build()
117122
}
118-
119-
abstract static class WarningsService implements BuildService<BuildServiceParameters.None>, AutoCloseable {
120-
@Override
121-
void close() throws Exception {
122-
Warnings.values().each {it.reset() }
123-
}
124-
}
125123
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicBoolean
66

77
enum Warnings {
88
MAYBE_SUPPORTED_ANDROID_VERSION("WARNING: Android plugin ${Versions.CURRENT_ANDROID_VERSION} has not been tested with this version of the Android cache fix plugin, although it may work. We test against only the latest patch release versions of Android Gradle plugin: ${Versions.SUPPORTED_ANDROID_VERSIONS.join(", ")}. If ${Versions.CURRENT_ANDROID_VERSION} is newly released, we may not have had a chance to release a version tested against it yet. Proceed with caution. You can suppress this warning with with -D${Versions.IGNORE_VERSION_CHECK_PROPERTY}=true."),
9-
USE_COMPILE_LIBRARY_RESOURCES_EXPERIMENTAL("WARNING: Android plugin ${Versions.CURRENT_ANDROID_VERSION} has experimental support for using relative path sensitivity with CompileLibraryResourcesTask inputs which will provide more build cache hits and will improve build speed. Set '${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=true' and '${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=true' in gradle.properties to enable this support.")
9+
USE_COMPILE_LIBRARY_RESOURCES_EXPERIMENTAL("WARNING: Android plugin ${Versions.CURRENT_ANDROID_VERSION} has experimental support for using relative path sensitivity with CompileLibraryResourcesTask inputs which will provide more build cache hits and improve build speed. Set '${CompileLibraryResourcesWorkaround_7_0.CACHE_COMPILE_LIB_RESOURCES}=true' and '${CompileLibraryResourcesWorkaround_7_0.ENABLE_SOURCE_SET_PATHS_MAP}=true' in gradle.properties to enable this support.")
1010

1111
final String warning
1212
private final AtomicBoolean warned = new AtomicBoolean()
@@ -24,4 +24,8 @@ enum Warnings {
2424
void reset() {
2525
warned.set(false)
2626
}
27+
28+
static void resetAll() {
29+
values().each {it.reset() }
30+
}
2731
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.gradle.android
2+
3+
import org.gradle.api.services.BuildService
4+
import org.gradle.api.services.BuildServiceParameters
5+
6+
abstract class WarningsService implements BuildService<BuildServiceParameters.None>, AutoCloseable {
7+
@Override
8+
void close() throws Exception {
9+
Warnings.resetAll()
10+
}
11+
}

0 commit comments

Comments
 (0)