How to prevents duplicate plugins?


(Horcrux7) #1

I receive the follow error message:

A problem occurred evaluating script.
> Failed to apply plugin [class 'de.undercouch.gradle.tasks.download.DownloadTaskPlugin']
   > Cannot add extension with name 'download', as there is an extension already registered with that name.

The cause is that we apply 2 different script plugins which apply the same plugin. The structure is like:

build.gradle
  apply from: "util1.gradle"
     apply plugin: de.undercouch.gradle.tasks.download.DownloadTaskPlugin
  apply from: "util2.gradle"
     apply plugin: de.undercouch.gradle.tasks.download.DownloadTaskPlugin

In the normal case we use only one of the both utils.gradle. But now we have a case in which we need both. Can we prevent the duplicate registration through adding a dependency if the plugin already exists?


(Horcrux7) #2

The solution is to change the apply plugin line to:

if( !project.plugins.hasPlugin( 'de.undercouch.download' ) ) apply plugin: de.undercouch.gradle.tasks.download.DownloadTaskPlugin


(Chris Doré) #3

From what I understand, the Gradle plugin management code is supposed to take care of this for you. Perhaps this is a bug.