I am trying to write a standalone plugin to be used by our team, that will replace common plugin application code in different projects and will apply some preset standard configuration to those plugins, as a convention to work by.
I was successful in configuring an external 3rd party plugin I am importing, inside my plugin code, but wasn’t able to propagate that dependency to the users of my custom plugin, so it seems.
When I apply my plugin, and run the build task - I get the following exception:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project
…
Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
…
Caused by: java.lang.NoClassDefFoundError: com/benjaminsproule/swagger/gradleplugin/GradleSwaggerPlugin
The generated jar file indeed doesn’t contain the above dependency, but I was expecting Gradle to download it. Am I mistaken? What is the best practice here? Is there some way I can instruct Gradle to download the dependency on its own, or should I bundle the 3rd party plugin with my plugin?
How are you consuming the plugin? Generally you would publish the plugin to an artifact repository with a POM that would contain dependencies. Gradle will download the dependencies when published this way.
In addition to what @jjustinic wrote I recommend that you deploy your plugin artifact to mavenLocal() aka ~/.m2/repository/com/example/your/plugin first in order to verify that it can be applied to a sample project.
Well because I was looking into this issues recently as I understand you would like to apply 'com.benjaminsproule.swagger.gradle.plugin' in your plugin and gradle should download it immediately.
For your information if in your plugin’s module you create a build.gradle file and add dependencies there when you apply your plugin Gradle should automatically add your plugin’s dependencies as classpath dependencies in the project you applied the plugin.
This should, in theory, bring the dependency as well, but it doesn’t happen.
Your dependencies section defines the swagger-gradle-plugin as compileOnly. I would think you’d put api here, for it to propagate to the users. I tried this and it didn’t work.
This should, in theory, bring the dependency as well, but it doesn’t happen.
No it should not. As I have said above in your plugin’s build.gradle file you should add the dependency.
Then in your pom.xml make sure the dependency is added and then Gradle will automatically download the dependency when your plugin is applied to a project.
I would think you’d put api here, for it to propagate to the users. I tried this and it didn’t work.
You do not need api. Those dependencies will be applied as classpath dependencies in the projects that your plugin is applied. Then Gradle should be able to recognize the 3rd party plugin you want to add