Update RewritePlugin to load tasks lazily #326
Merged
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.
What's changed?
The RewritePlugin was changed to call the register() method instead of the create() method for the three tasks. This method takes a configuration lambda where the existing configuration can be done. Next, the tasks' usages were replaced with the equivalent TaskProvider reference. Finally, fetching the appropriate JavaCompile tasks was updated to use a lazy load method (named()), so those tasks are not eagerly created. The plugin's Gradle version was unchanged and should still support Gradle 4.10.
What's your motivation?
The current structure of RewritePlugin eagerly loads the RewriteRun, RewriteDryRun, and RewriteDiscover tasks. This is a problem in Gradle builds with a large number of modules, as it has to create hundreds or even thousands of tasks during configuration. This will happen even if the tasks are not used in that run. This commit updates the plugin by lazily loading these tasks to avoid this issue.