BuildScript, Plugin and multiple files

Hello,

I’m working on multiple project and i want to have common files to setup build.

I’d like to have only the build.gradle specific to the project and have files to include and configure plugins.

When I put everything in my build.gradle, everything is ok. When I separate in files (and include files in build.gradle) it fails to find plugin

Exemple :

==== build.gradle====

buildscript {
repositories {
ivy {
name = “repo-spotless”
}
}
dependencies {
classpath “com.diffplug.spotless:spotless-plugin-gradle:3.0.0”
}
}
apply plugin: ‘com.diffplug.gradle.spotless’

=> if i put this into a “spotless.gradle” which is included by build.gradle it fails.

====build.gradle====
apply from: ‘spotless.gradle’

====spotless.gradle====
buildscript {
repositories {
ivy {
name = “repo-spotless”
}
}
dependencies {
classpath “com.diffplug.spotless:spotless-plugin-gradle:3.0.0”
}
}
apply plugin: ‘com.diffplug.gradle.spotless’

Any idea why ? maybe this is easy but I search the web and found nothing.

Thanks.

I think you are hit by a limitation in the way plugin IDs are resolved in an applied build script, which is described in Github issue 1262. There are some work-arounds suggested in the comments to that issue.

1 Like

There are definite and confusing limitations w.r.t to what you have attempted.

In your case you are going to be better off by hiding as much as you can in buildSrc and then just apply custom plugins that you have created in buildSrc.

Thanks you all for your answears.

The simplest way for me is to put the same piece of code everywhere :frowning: