Apply JavaPlugin conditionally #12
Open
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.
Before this PR
The revapi-gradle-plugin unconditionally applies the org.gradle.api.plugins.JavaPlugin to any project it is applied to. This causes a conflict and build failure (e.g., "Cannot add task 'test' as a task with that name already exists") if another plugin that provides Java capabilities (like com.android.library, com.android.application, or even java-library itself) has already been applied to the project. This limits the plugin's applicability in common Gradle setups, especially for Android projects or multi-project builds where base Java functionality is established by other dedicated plugins.
After this PR
The revapi-gradle-plugin will now conditionally apply the org.gradle.api.plugins.JavaPlugin. It first checks if the project already has a compatible Java plugin (java, java-library, com.android.library, com.android.application) applied. If such a plugin is detected, revapi-gradle-plugin will skip applying JavaPlugin itself, thus avoiding task registration conflicts.
Possible downsides?
Not that I can think of since JavaPlugin will still be applied in other cases.