I'm attempting to include a Git submodule as a subproject to my primary Gradle project, but Gradle refuses to validate the build script on the grounds that the both my project and the subproject require the same plugin ("Plugin request for plugin already on the classpath must not include a version"
).
Removing the plugin from the primary project isn't an option, since the tasks defined by the plugin will no longer be available to the primary build script. Nor is omitting the plugin version from the primary build script, since that's the first instance of the plugin declaration that Gradle sees (while the error is thrown on the declaration in the subproject).
Ordinarily I'd have my project patch out such an incompatibility, but since the build script doesn't validate, this obviously isn't an option. What can be done to resolve the conflict given that I have effectively no control over the subproject's build script?
The Gradle build system in Android Studio makes it easy to include external binaries or other library modules to your build as dependencies. The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well.
The subproject producer defines a task named buildInfo that generates a properties file containing build information e.g. the project version. You can then map the task provider to its output file and Gradle will automatically establish a task dependency. Example 2.
Applying a plugin to a project allows the plugin to extend the project's capabilities. It can do things such as: Extend the Gradle model (e.g. add new DSL elements that can be configured) Configure the project according to conventions (e.g. add new tasks or configure sensible defaults)
There are two general types of plugins in Gradle, script plugins and binary plugins.
I had a similar problem, I wanted to include a module which should also be able to be built on its own. More precise, the module which I wanted to include also declared com.github.johnrengelman.shadow
for producing a runnable JAR. That resulted in two build.gradle files declaring this plugin with a version number.
The solution is to use a Composite Build. That causes the module's build to be completely separate, being able to declare plugins with any version whatsoever.
All you have to do is to add includeBuild "<pathToSubmodule>"
in your root settings.gradle:
includeBuild "../submodule"
Then you can define the submodule as a normal dependency in your toplevel build.gradle:
dependencies {
implementation 'com.mycompany:submodule:1.0-SNAPSHOT'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With