Skip to content

Commit 8122268

Browse files
authored
Merge pull request #133 from gradle/gh/7.0-fixes
Updates to make plugin compatible with Gradle 7.0
2 parents 341894e + d16a7d5 commit 8122268

9 files changed

+324
-222
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ Please star them if you are experiencing them in your project.
5858
* DexFileDependenciesTask is not cacheable: https://issuetracker.google.com/160138798
5959
* MergeResources is not relocatable: https://issuetracker.google.com/issues/141301405
6060
* Room annotation processor causes cache misses, doesn't declare outputs, overlapping outputs, etc: https://issuetracker.google.com/issues/132245929
61+
62+
## Implementation Notes
63+
64+
### RoomSchemaLocationWorkaround
65+
66+
Most of the workarounds in this plugin should apply to your project without any changes. However, one workaround
67+
requires some extra configuration. The Room schema location workaround allows you to specify an output directory for
68+
Room schema exports without breaking caching for your Java and/or Kapt tasks where the annotation processor has been configured.
69+
There are various issues with how this annotation processor works (see https://issuetracker.google.com/issues/132245929
70+
and https://issuetracker.google.com/issues/139438151) which this workaround attempts to mitigate. However, in order to
71+
do so in a manageable way, it imposes some restrictions:
72+
73+
* The schema export directory must be configured via the "room" project extension instead of as an explicit annotation
74+
processor argument. If an explicit annotation processor argument is provided, an exception will be thrown, instructing
75+
the user to configure it via the extension:
76+
```
77+
room {
78+
schemaLocationDir = file("roomSchemas")
79+
}
80+
```
81+
* There can only be a single schema export directory for the project - you cannot configure variant-specific export
82+
directories. Schemas exported from different variants will be merged in the directory specified in the "room" extension.

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ version = ["git", "describe", "--match", "[0-9]*", "--dirty"].execute().text.tri
1313

1414
// Maps supported Android plugin versions to the versions of Gradle that support it
1515
def supportedVersions = [
16-
"4.2.0-beta03": ["6.7.1"],
17-
"4.1.2": ["6.5.1"],
18-
"4.0.2": ["6.1.1", "6.3", "6.4.1"],
19-
"3.6.4": ["5.6.4", "6.3", "6.4.1"],
20-
"3.5.4": ["5.4.1", "5.6.4", "6.3", "6.4.1"]
16+
"4.2.0-beta03": ["6.8.1", "7.0-20210119173355+0000"],
17+
"4.1.1": ["6.5.1", "6.8.1"],
18+
"4.0.2": ["6.1.1", "6.8.1"],
19+
"3.6.4": ["5.6.4", "6.8.1"],
20+
"3.5.4": ["5.4.1", "5.6.4", "6.8.1"]
2121
]
2222

2323
repositories {

src/main/groovy/org/gradle/android/workarounds/AbstractAbsolutePathWorkaround.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ abstract class AbstractAbsolutePathWorkaround implements Workaround {
1919
void apply(WorkaroundContext context) {
2020
Project project = context.project
2121
project.tasks.withType(androidTaskClass).configureEach { Task task ->
22-
FileCollection originalPropertyValue
22+
FileCollection originalPropertyValue = project.files()
2323
// Create a synthetic input with the original property value and RELATIVE path sensitivity
24+
task.inputs.files(originalPropertyValue)
25+
.withPathSensitivity(PathSensitivity.RELATIVE)
26+
.withPropertyName("${propertyName}.workaround")
27+
.optional()
2428
project.gradle.taskGraph.beforeTask {
2529
if (it == task) {
26-
originalPropertyValue = task.getProperty(propertyName)
30+
originalPropertyValue.from(task.getProperty(propertyName))
2731
setPropertyValue(task, project.files())
28-
task.inputs.files(originalPropertyValue)
29-
.withPathSensitivity(PathSensitivity.RELATIVE)
30-
.withPropertyName("${propertyName}.workaround")
31-
.optional()
3232
}
3333
}
3434
// Set the task property back to its original value

src/main/groovy/org/gradle/android/workarounds/CompileLibraryResourcesWorkaround_4_0.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class CompileLibraryResourcesWorkaround_4_0 implements Workaround {
3232
void apply(WorkaroundContext context) {
3333
Project project = context.project
3434
project.tasks.withType(androidTaskClass).configureEach { Task task ->
35-
DirectoryProperty originalPropertyValue
35+
DirectoryProperty originalPropertyValue = project.objects.directoryProperty()
3636
// Create a synthetic input with the original property value and RELATIVE path sensitivity
37+
task.inputs.dir(originalPropertyValue)
38+
.withPathSensitivity(PathSensitivity.RELATIVE)
39+
.withPropertyName("${propertyName}.workaround")
40+
.optional()
3741
project.gradle.taskGraph.beforeTask {
3842
if (it == task) {
39-
originalPropertyValue = task.getProperty(propertyName)
43+
originalPropertyValue.set(task.getProperty(propertyName))
4044
def dummyProperty = project.objects.directoryProperty()
4145
// Non-existent file to give the DirectoryProperty a value.
4246
dummyProperty.set(project.file('/doesnt-exist'))
4347
setPropertyValue(task, dummyProperty)
44-
task.inputs.dir(originalPropertyValue)
45-
.withPathSensitivity(PathSensitivity.RELATIVE)
46-
.withPropertyName("${propertyName}.workaround")
47-
.optional()
4848
}
4949
}
5050
// Set the task property back to its original value

src/main/groovy/org/gradle/android/workarounds/CompileLibraryResourcesWorkaround_4_2.groovy

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ class CompileLibraryResourcesWorkaround_4_2 implements Workaround {
3434
void apply(WorkaroundContext context) {
3535
Project project = context.project
3636
project.tasks.withType(androidTaskClass).configureEach { Task task ->
37-
ConfigurableFileCollection originalPropertyValue
37+
ConfigurableFileCollection originalPropertyValue = project.files()
3838
// Create a synthetic input with the original property value and RELATIVE path sensitivity
39+
task.inputs.files(originalPropertyValue)
40+
.withPathSensitivity(PathSensitivity.RELATIVE)
41+
.withPropertyName("${propertyName}.workaround")
42+
.optional()
3943
project.gradle.taskGraph.beforeTask {
4044
if (it == task) {
41-
originalPropertyValue = task.getProperty(propertyName)
45+
originalPropertyValue.from(task.getProperty(propertyName))
4246
def dummyProperty = project.objects.fileCollection()
4347
// Non-existent file to give the ConfigurableFileCollection a value.
4448
dummyProperty.setFrom(project.file('/doesnt-exist'))
4549
setPropertyValue(task, dummyProperty)
46-
task.inputs.files(originalPropertyValue)
47-
.withPathSensitivity(PathSensitivity.RELATIVE)
48-
.withPropertyName("${propertyName}.workaround")
49-
.optional()
5050
}
5151
}
5252
// Set the task property back to its original value

src/main/groovy/org/gradle/android/workarounds/MergeResourcesWorkaround.groovy

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.gradle.android.AndroidIssue
44
import org.gradle.api.Project
55
import org.gradle.api.Task
66
import org.gradle.api.file.FileCollection
7+
import org.gradle.api.provider.MapProperty
78
import org.gradle.api.tasks.PathSensitivity
89

910
/**
@@ -21,20 +22,20 @@ class MergeResourcesWorkaround implements Workaround {
2122
void apply(WorkaroundContext context) {
2223
Project project = context.project
2324
project.tasks.withType(androidTaskClass).configureEach { Task task ->
24-
Map<String, FileCollection> originalResources = [:]
25+
MapProperty<String, FileCollection> originalResources = project.objects.mapProperty(String, FileCollection)
2526
// Create a synthetic input with the original value and RELATIVE path sensitivity
27+
task.inputs.files(originalResources.map {it.values() })
28+
.withPathSensitivity(PathSensitivity.RELATIVE)
29+
.withPropertyName("rawLocalResources.workaround")
2630
project.gradle.taskGraph.beforeTask {
2731
if (it == task) {
28-
originalResources.putAll(task.resourcesComputer.resources)
32+
task.resourcesComputer.resources.each { key, value -> originalResources.put(key, value) }
2933
task.resourcesComputer.resources.clear()
30-
task.inputs.files(originalResources.values())
31-
.withPathSensitivity(PathSensitivity.RELATIVE)
32-
.withPropertyName("rawLocalResources.workaround")
3334
}
3435
}
3536
// Set the source back to its original value before we execute the main task action
3637
task.doFirst {
37-
task.resourcesComputer.resources.putAll(originalResources)
38+
task.resourcesComputer.resources.putAll(originalResources.get())
3839
}
3940
}
4041
}

0 commit comments

Comments
 (0)