Skip to content

Commit 3d57ec4

Browse files
committed
Don't clean out merge directory before merging
1 parent aa3676a commit 3d57ec4

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import java.lang.reflect.Field
3333
* aforementioned merge task. Note that this workaround only works with Kotlin Gradle plugin 1.3.70 or
3434
* higher.
3535
*
36+
* There are multiple issues related to these problems:
37+
* - https://issuetracker.google.com/issues/132245929
38+
* - https://issuetracker.google.com/issues/139438151
3639
*/
3740
@AndroidIssue(introducedIn = "3.5.0", fixedIn = [], link = "https://issuetracker.google.com/issues/132245929")
3841
class RoomSchemaLocationWorkaround implements Workaround {
@@ -106,7 +109,9 @@ class RoomSchemaLocationWorkaround implements Workaround {
106109
)
107110

108111
// Change the room schema location back to an absolute path right before the kapt tasks execute.
109-
// This allows other annotation processors that rely on the path being absolute to still function.
112+
// This allows other annotation processors that rely on the path being absolute to still function and
113+
// makes it resilient when the working directory is something other than the project directory.
114+
// See https://issuetracker.google.com/issues/139438151
110115
project.plugins.withId("kotlin-kapt") {
111116
project.tasks.withType(kaptWithoutKotlincTaskClass).configureEach { Task task ->
112117
task.finalizedBy mergeTask
@@ -313,7 +318,6 @@ class RoomSchemaLocationWorkaround implements Workaround {
313318
@TaskAction
314319
void mergeSourcesToDestinations() {
315320
roomSchemaMergeLocations.mergeAssociations.each { destination, source ->
316-
project.delete(destination)
317321
println "Merging schemas to ${destination}"
318322
project.copy {
319323
duplicatesStrategy(DuplicatesStrategy.INCLUDE)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ class RoomSchemaLocationWorkaroundTest extends AbstractTest {
231231
232232
void assertMergedSchemaOutputsExist() {
233233
// Merged schemas
234+
assert file("app/schemas/org.gradle.android.example.app.AppDatabase/1.json").exists()
234235
assert file("app/schemas/org.gradle.android.example.app.AppDatabase/2.json").exists()
236+
assert file("library/schemas/org.gradle.android.example.library.AppDatabase/1.json").exists()
235237
assert file("library/schemas/org.gradle.android.example.library.AppDatabase/2.json").exists()
236238
}
237239
}

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

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ class SimpleAndroidApp {
257257
258258
@ColumnInfo(name = "last_name")
259259
public String lastName;
260+
261+
@ColumnInfo(name = "last_update")
262+
public int lastUpdate;
260263
}
261264
""".stripIndent()
262265

@@ -329,6 +332,55 @@ class SimpleAndroidApp {
329332
}
330333
""".stripIndent()
331334

335+
file("${basedir}/schemas/${packageName}.AppDatabase/1.json") << '''
336+
{
337+
"formatVersion": 1,
338+
"database": {
339+
"version": 1,
340+
"identityHash": "ce7bbbf6ddf39482eddc7248f4f61e8a",
341+
"entities": [
342+
{
343+
"tableName": "user",
344+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uid` INTEGER NOT NULL, `first_name` TEXT, `last_name` TEXT, PRIMARY KEY(`uid`))",
345+
"fields": [
346+
{
347+
"fieldPath": "uid",
348+
"columnName": "uid",
349+
"affinity": "INTEGER",
350+
"notNull": true
351+
},
352+
{
353+
"fieldPath": "firstName",
354+
"columnName": "first_name",
355+
"affinity": "TEXT",
356+
"notNull": false
357+
},
358+
{
359+
"fieldPath": "lastName",
360+
"columnName": "last_name",
361+
"affinity": "TEXT",
362+
"notNull": false
363+
}
364+
],
365+
"primaryKey": {
366+
"columnNames": [
367+
"uid"
368+
],
369+
"autoGenerate": false
370+
},
371+
"indices": [],
372+
"foreignKeys": []
373+
}
374+
],
375+
"views": [],
376+
"setupQueries": [
377+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
378+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'ce7bbbf6ddf39482eddc7248f4f61e8a')"
379+
]
380+
}
381+
}
382+
'''.stripIndent()
383+
332384
file("${basedir}/src/main/res/layout/${resourceName}_layout.xml") << '''<?xml version="1.0" encoding="utf-8"?>
333385
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
334386
android:orientation="vertical"

0 commit comments

Comments
 (0)