I am studying how to write a custom Gradle plugin, using the composite build strategy (use includeBuild
to add the custom plugin into the main project) as detailed here.
Here is how my project is structured:
If I need to include an external library in my custom plugin, say, 'org.apache.commons:commons-lang3:3.6'
, I get an error saying that no repositories is defined.
Does the repositories defined (using dependencyResolutionManagement
) inside the main project level settings.gradle
not apply to the custom plugin project?
Here is what my top levelsettings.gradle
looks like:
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "LocalJavaGradlePlugin"
include ':app'
includeBuild('customPlugins')
I tried copy pasting the same dependencyResolutionManagement
block to the settings.gradle
file of the custom plugin, as shown here:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = 'myfirstplugin'
, but I now get an error saying: “Build was configured to prefer settings repositories over project repositories but repository ‘Gradle Libs’ was added by unknown code”. I can change repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
to PREFER_SETTINGS
, but now I get that same message over and over as warnings, even if it is no longer an error. So this doesn’t feel like it’s the correct way to proceed either.
Any suggestions on what is the correct way to handle dependency for a custom plugin?