How can I conditionally run code if a Gradle plugin is applied?

Viewed 3125

I have a script plugin that I would like to:

  • Check if the ivy-publish applied (via apply plugin: ivy-publish):
  • If it is applied, declare publishing { repositories { ivy { } } }
  • If it's not applied, run some other code

However, I'm unsure of how to actually run code if the ivy-publish plugin is applied, and I couldn't find anything about that in the documentation. Is there any way to do this?

3 Answers

Or use:

if (project.getPluginManager().hasPlugin("ivy-publish")) {
    ..
}
Related