Now I am creating a new plugin that should incorporate the above plugin and force some of the configuration elements on the project where the plug-in is applied to.
I have the basic code for my groovy based plugin, like this
but when the consumer uses this plugin it raises an error
FAILURE: Build failed with an exception.
Where:
Build file '/Users/andreas/eclipse-workspace/tester/build.gradle' line: 12
* What went wrong:
An exception occurred applying plugin request [id: 'com.bisiach.gradle.custom-plugin', version: '1.0.0']
> Failed to apply plugin [id 'com.bisiach.gradle.custom-plugin']
> Cannot change dependencies of configuration ':classpath' after it has been resolved.
Unfortunately I discovered the neither my approach or the one in the guide work.
I will use the terminology in the guide to be more clear.
In my scenario the Base Plugin (the capability plugin) is published public here:
On the other hand, the āconventionā plugin will be published privately to a company maven repo. The plugin named i.e: com.acme.gradle.standard-development-plugin.
The idea is that this plug-in will be applied to all customer projects using gradle.init.
During develompent, to test com.acme.gradle.standard-development-plugin I am using composite build.
I have a project ātestā that includes the build of com.acme.gradle.standard-development-plugin. In this scenario, adding the following to build.gradle of com.acme.gradle.standard-development-plugin worked. but only because in a composite build, the project ātestā can see the runtime dependency:
After publishing my com.acme.gradle.standard-development-plugin to an internal maven repo, and including in the project ātestā as a normal plugin, the plug in fails to apply the base (capability) plugin com.bisiach.gradle.gitversion-plugin.
The examples outlined in the guide always shoes capability and convention plugins coming from the same gradle build. That is why it works there I think.
I need to achieve the same between 2 plugins coming from 2 different builds/repositories
Thereās a good chance something like that could work, if you hadnāt tried it yet.
Please let us know if it does or not? Thanks.
EDIT: Actually, I see that you have tried something similar beforeā¦
Have you tried it with the class literal (.class) of the plugin you want to apply? Like itās done in the Gradle source links? Instead of the pluginās id string?
Did anyone end up getting this working? Iām also trying to get this working but have had issues (the plugins are actually in completely different repos that Iām trying to incorporate)
The Issue with the above mentioned solutions is that they declared the dependency in the plugins build.gradle file as runtime. Thatās why you can not apply the Plugin class (as it is missing in the compile classpath). Just change the dependency to implementation.
I donāt think that any lazy configuration will help here as one usually wants to interact with the other plugins datastructures and therefor youāll need access to the classes on the compileClasspath and runtimeClasspath what the implementation configuration is meant for.
Well this is by design. Even when doing it from inside your convinience plugin you technically do write apply plugin: 'includedPluginId' and this will add all Tasks, Configurations etc. to your project and thus itās namespace. Iām pretty sure this is intentional and can not be avoided.
Does that mean I cannot dynamically choose a version for the 3rd party plugin I want to apply? I would like the userās configuration (maybe indirectly) to affect the version of the plugin I will apply from my plugin. How can I do that?
There is very VERY shady way to do that by hacking the settings ClassLoaderScope, but Iād rather notā¦
The user could use a dependency constraint in the buildscript { ... } block to influence the version, or you could require the user to add the plugin in the wanted version to the buildscritpās classpath.