Reputation: 7289
I am using Gradle as a build tool for my Scala projects. I am also using Eclipse for development, so I always use the apply plugin: 'eclipse'
in my build files.
Is there also a way to define the apply plugin
globally? SBT already has such a feature. The reason why I want this, is that other developers who’re using my project probably don’t use Eclipse but another IDE and they would have to change the build script for their needs. If there were a global configuration file, one could put personal configurations in there and it wouldn’t conflict other ones.
Upvotes: 5
Views: 2385
Reputation: 8443
for the accepted answer, I also got the error message "The root project is not yet available for build".
I am using gradle 7.6 and I was trying to use the Gradle Test Logger Plugin
Here's the ~/.gradle/init.gradle
that worked for me:
initscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'com.adarshr:gradle-test-logger-plugin:3.2.0'
}
}
allprojects {
apply plugin: com.adarshr.gradle.testlogger.TestLoggerPlugin
}
There are multiple things to be aware of when configuring a 3rd party plugin globally:
The last two points are described in the Gradle Forums question Cannot apply plugin by id in init.gradle script.
If you wonder what the implementation class is for your plugin, here's how I found it for the Gradle Test Logger Plugin:
gradlePlugin {
implementationClass
Upvotes: 0
Reputation: 123996
You can put this into ~/.gradle/init.gradle
:
rootProject.allprojects {
apply plugin: "eclipse"
}
The drawback of this approach is that it makes the build less reproducible. People now need to add something to their init.gradle
to make (some aspect of) the build work. Therefore, I would recommend to apply the Eclipse plugin in the main build script; it won't hurt people who don't use it.
Upvotes: 7
Reputation: 33476
You could create a build.gradle
in buildSrc which implements your custom logic. Just don't check it into version control. To apply it to multiple projects you could create a central buildSrc
directory and create symbolic links in the projects that you want to apply it to.
Upvotes: -1