Slackbot
08/29/2023, 9:51 AMThomas Broyer
08/29/2023, 9:55 AMincludeBuild Gradle won't automatically add the dependency. plugins {} implicitly adds a dependency, that Gradle will resolve to the included build. But to be able to use apply plugin: you'll first have to add the included build as a dependency to the buildscript classpath, as with any third-party plugin. buildSrc is always part of the buildscript's classloader, so it Just Works™ without any additional ceremony.ephemient
08/29/2023, 10:06 AMbuildscript {
dependencies {
classpath("binary.name.of:included-build")
}
}Vampire
08/29/2023, 10:11 AMplugins {
id("...") apply false
}Vampire
08/29/2023, 10:13 AMapply(...) is legacy and discouraged.
You usually shouldn't use it, but always use the plugins { ... } block.
And if there is a legit reason to not use the plugins { ... } block, it is most probably a bug.Piotr Minkina
08/29/2023, 10:16 AMbuildscript {
dependencies {
classpath("binary.name.of:included-build")
}
}
it looks like it's not working. Tested in Gradle 8.2.1Piotr Minkina
08/29/2023, 10:24 AMapply plugin: ''. At the same time I don't want to make any copies of the sources, etc. (as little repeated code as possible). Currently I have a buildSrc/settings.gradle file with the following content and it works as it should. However, I can't get the same effect with the pluginManagement { includeBuild('plugin/') } declaration.
// buildSrc/settings.gradle
rootProject.projectDir = file('../')
// build.gradle
if (gradle.rootBuild) {
apply plugin: 'com.example.plugin'
}Piotr Minkina
08/29/2023, 10:27 AMPiotr Minkina
08/29/2023, 10:32 AMplugins block does not conditionally allow plugins to be included.
plugins {
id 'com.example.plugin` apply false
}Vampire
08/29/2023, 10:37 AMbuildSrc build?
That sounds pretty scary. 😱Piotr Minkina
08/29/2023, 10:48 AMincludeBuild(). Some plugins, like the documentation generation plugin attaches itself to generate documentation in HTML, based on Markdown files.
If I set up the project so that the plugin sources are in the plugin/ directory, which I include in settings.gradle using includeBuild('plugin/'), it will build itself and in the main project I can use it to generate documentation. In such a version, the comfort of working in the command line deteriorates, because I have to specify the path to the plugin tasks every time, for example ./gradlew :plugin:check. Besides, the configuration of such a plugin deviates more from the configuration of other plugins, where the need for self-including is not present.Vampire
08/29/2023, 10:52 AM./gradlew plugincheckOnly if there are
check task in other projects of the build that you want to not execute. 🙂
Well, try to do the includeBuild outside the pluginManagement block.
I doubt it, but maybe that makes it found in the buildscript dependencies.
If so, it would imho be strange actually though. 😄Piotr Minkina
08/29/2023, 10:56 AMincludeBuild() outside the pluginManagement {} block and it didn't work either. If I had to mess around with pluginManagement { includeBuild('plugin/') } then I think I will stay with buildSrc/ with only one file, which is settings.gradle. Very simple solution and fulfills everything I need.Piotr Minkina
08/29/2023, 11:11 AMpluginManagement { includeBuild('../another-plugin/') }.
// buildSrc/settings.gradle
if (gradle.identityPath.path != ':buildSrc') {
return
}
rootProject.with {
name = gradle.parent.rootProject.name
projectDir = file('../')
}
// settings.gradle
if (gradle.rootBuild) {
gradle.afterProject { p ->
p.apply plugin: 'com.example.another-plugin'
}
}
rootProject.name = 'another-plugin'
or instead of `settings.gradle`:
// build.gradle
if (gradle.rootBuild) {
apply plugin: 'com.example.another-plugin'
}