Skip to content

Commit 937b5dd

Browse files
committed
Update the "Automated Migration" page
This PR updates the [Automated Migration](https://robolectric.org/automated-migration/) page. The changes are: - Adding Kotlin code sample. - Update the procedure to match recent versions of Error Prone.
1 parent 72af34a commit 937b5dd

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

docs/automated-migration.md

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,72 @@ Robolectric provides an automated migration tool to help keep your test suite up
1010

1111
The migration tool will make changes directly to source files in your codebase, which you can review and commit to your source control system.
1212

13-
***Before*** updating your dependencies to the new version of Robolectric:
13+
**Before** updating your dependencies to the new version of Robolectric:
1414

1515
1. Make sure you're using a recent version of Gradle (4.10 or newer).
1616

17-
2. [Configure your project](https://errorprone.info/docs/installation) to compile using Error Prone. Quick config for Gradle (usually in `app/build.gradle`):
17+
2. [Configure your project](https://errorprone.info/docs/installation) to integrate Error Prone. Quick config for Gradle (usually in your module's `build.gradle`/`build.gradle.kts` file):
18+
19+
=== "Groovy"
1820

1921
```groovy
2022
plugins {
21-
id "net.ltgt.errorprone" version "0.6" apply false
23+
id "net.ltgt.errorprone" version "<error_prone_plugin_version>" apply false
2224
}
2325

24-
String roboMigration = System.getenv("ROBOLECTRIC_MIGRATION")
25-
if (roboMigration) {
26+
String robolectricMigrations = System.getenv("ROBOLECTRIC_MIGRATIONS")
27+
if (robolectricMigrations) {
2628
apply plugin: "net.ltgt.errorprone"
2729

2830
dependencies {
29-
errorprone "com.google.errorprone:error_prone_core:2.3.2"
30-
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1"
31-
31+
errorprone "com.google.errorprone:error_prone_core:<error_prone_version>"
3232
errorprone "org.robolectric:errorprone:{{ robolectric.version.current }}"
3333
}
3434

35-
afterEvaluate {
36-
tasks.withType(JavaCompile) { t ->
37-
options.errorprone.errorproneArgs += [
38-
'-XepPatchChecks:' + roboMigration,
39-
'-XepPatchLocation:IN_PLACE',
40-
]
41-
}
35+
tasks.withType(JavaCompile).configureEach {
36+
options.errorprone.errorproneArgs = [
37+
'-XepPatchChecks:' + robolectricMigrations,
38+
'-XepPatchLocation:IN_PLACE',
39+
]
40+
}
41+
}
42+
```
43+
44+
=== "Kotlin"
45+
46+
```kotlin
47+
plugins {
48+
id("net.ltgt.errorprone") version "<error_prone_plugin_version>" apply false
49+
}
50+
51+
val robolectricMigrations = System.getenv("ROBOLECTRIC_MIGRATIONS")
52+
if (!robolectricMigrations.isNullOrEmpty()) {
53+
pluginManager.apply("net.ltgt.errorprone")
54+
55+
dependencies {
56+
errorprone("com.google.errorprone:error_prone_core:<error_prone_version>")
57+
errorprone("org.robolectric:errorprone:{{ robolectric.version.current }}")
4258
}
59+
60+
tasks.withType<JavaCompile>().configureEach {
61+
options.errorprone.errorproneArgs = listOf(
62+
"-XepPatchChecks:$robolectricMigrations",
63+
"-XepPatchLocation:IN_PLACE",
64+
)
65+
}
4366
}
4467
```
4568

4669
You don't need to commit this change.
4770

48-
3. Run the migrations. Due to limitations of Error Prone, you'll need to manually do this in a couple steps:
71+
3. Run the migrations:
4972

5073
```bash
51-
ROBOLECTRIC_MIGRATION=DeprecatedMethods ./gradlew clean :compileDebugUnitTestJava
52-
ROBOLECTRIC_MIGRATION=ShadowUsageCheck ./gradlew clean :compileDebugUnitTestJava
74+
ROBOLECTRIC_MIGRATION=DeprecatedMethods,ShadowUsageCheck ./gradlew clean :compileDebugUnitTestJava
5375
```
5476

5577
4. Make sure your code still compiles and commit changes.
5678

5779
5. Update your project to the new version of Robolectric.
5880

59-
The migration tool will make a best effort attempt to adjust source, but there might be more complicated situations that it cannot handle and that need to be converted manually.
81+
The migration tool will make a best effort attempt to adjust the source code, but there might be more complicated situations that it cannot handle and that need to be converted manually.

0 commit comments

Comments
 (0)