2

Below is a example where, in order to add a custom-plugin to the application, we need to specify it dependency in resolution strategy and by using useModule, to add it in classpath

-------build.gradle----------
plugins {
  id 'custom-plugin'
}
-------settings.gradle----------
 pluginManagement {
    resolutionStrategy {
      eachPlugin {
        if (requested.id.namespace == 'custom-plugin') {
            useModule('org.gradle.sample:custom-plugins:1.0.0')
        }
      }
    }
    repositories {
       maven { url 'maven-repo'  }
    }
}

Is there any simpler/better way to add the dependency (useModule section)?

I don't want to add if condition and check the namespace requested.id.namespace every time for any new custom plugin I add.

Is there a way to avoid this just like in the old way of adding plugin in the application, wherein buildscript block we just have to add that dependency using classpath.

buildscript {
repositories {
    maven { url "https://privaterepo.myemployer.com" }
}

dependencies {
    classpath "org.gradle.sample:custom-plugins:1.0.0"
}
Dan
  • 651
  • 1
  • 14
  • 31

1 Answers1

0

This depends, if the repository knows the requested requested.id.id, with the default .gradle.plugin suffix added. Your question led to another answer - and the example which I provide there, probably shows when it's required to use resolutionStrategy and when not.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216