-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the "Automated Migration" page #313
Merged
MGaetan89
merged 1 commit into
robolectric:master
from
MGaetan89:update_automated_migration
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,50 +10,72 @@ Robolectric provides an automated migration tool to help keep your test suite up | |
|
||
The migration tool will make changes directly to source files in your codebase, which you can review and commit to your source control system. | ||
|
||
***Before*** updating your dependencies to the new version of Robolectric: | ||
**Before** updating your dependencies to the new version of Robolectric: | ||
|
||
1. Make sure you're using a recent version of Gradle (4.10 or newer). | ||
|
||
2. [Configure your project](https://errorprone.info/docs/installation) to compile using Error Prone. Quick config for Gradle (usually in `app/build.gradle`): | ||
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): | ||
|
||
=== "Groovy" | ||
|
||
```groovy | ||
plugins { | ||
id "net.ltgt.errorprone" version "0.6" apply false | ||
id "net.ltgt.errorprone" version "<error_prone_plugin_version>" apply false | ||
} | ||
|
||
String roboMigration = System.getenv("ROBOLECTRIC_MIGRATION") | ||
if (roboMigration) { | ||
String robolectricMigrations = System.getenv("ROBOLECTRIC_MIGRATIONS") | ||
if (robolectricMigrations) { | ||
apply plugin: "net.ltgt.errorprone" | ||
|
||
dependencies { | ||
errorprone "com.google.errorprone:error_prone_core:2.3.2" | ||
errorproneJavac "com.google.errorprone:javac:9+181-r4173-1" | ||
|
||
errorprone "com.google.errorprone:error_prone_core:<error_prone_version>" | ||
errorprone "org.robolectric:errorprone:{{ robolectric.version.current }}" | ||
} | ||
|
||
afterEvaluate { | ||
tasks.withType(JavaCompile) { t -> | ||
options.errorprone.errorproneArgs += [ | ||
'-XepPatchChecks:' + roboMigration, | ||
'-XepPatchLocation:IN_PLACE', | ||
] | ||
} | ||
tasks.withType(JavaCompile).configureEach { | ||
options.errorprone.errorproneArgs = [ | ||
'-XepPatchChecks:' + robolectricMigrations, | ||
'-XepPatchLocation:IN_PLACE', | ||
] | ||
} | ||
} | ||
``` | ||
|
||
=== "Kotlin" | ||
|
||
```kotlin | ||
plugins { | ||
id("net.ltgt.errorprone") version "<error_prone_plugin_version>" apply false | ||
} | ||
|
||
val robolectricMigrations = System.getenv("ROBOLECTRIC_MIGRATIONS") | ||
if (!robolectricMigrations.isNullOrEmpty()) { | ||
pluginManager.apply("net.ltgt.errorprone") | ||
|
||
dependencies { | ||
errorprone("com.google.errorprone:error_prone_core:<error_prone_version>") | ||
errorprone("org.robolectric:errorprone:{{ robolectric.version.current }}") | ||
} | ||
|
||
tasks.withType<JavaCompile>().configureEach { | ||
options.errorprone.errorproneArgs = listOf( | ||
"-XepPatchChecks:$robolectricMigrations", | ||
"-XepPatchLocation:IN_PLACE", | ||
) | ||
} | ||
} | ||
``` | ||
|
||
You don't need to commit this change. | ||
|
||
3. Run the migrations. Due to limitations of Error Prone, you'll need to manually do this in a couple steps: | ||
3. Run the migrations: | ||
|
||
```bash | ||
ROBOLECTRIC_MIGRATION=DeprecatedMethods ./gradlew clean :compileDebugUnitTestJava | ||
ROBOLECTRIC_MIGRATION=ShadowUsageCheck ./gradlew clean :compileDebugUnitTestJava | ||
ROBOLECTRIC_MIGRATION=DeprecatedMethods,ShadowUsageCheck ./gradlew clean :compileDebugUnitTestJava | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that it is now possible to pass multiple checks at once. See https://errorprone.info/docs/patching |
||
``` | ||
|
||
4. Make sure your code still compiles and commit changes. | ||
|
||
5. Update your project to the new version of Robolectric. | ||
|
||
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. | ||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I could see, this dependency is added automatically by the Gradle plugin, for specific Java versions:
https://github.com/tbroyer/gradle-errorprone-plugin/blob/e22bbca556aca14bc10e34324675877c67ad5f0e/src/main/kotlin/net/ltgt/gradle/errorprone/ErrorPronePlugin.kt#L103-L111