Radosław Panuszewski
10/07/2024, 3:41 PMRadosław Panuszewski
10/07/2024, 3:41 PMrootProject {
buildscript {
dependencies {
// just some random plugin, doesn't matter
classpath("com.coditory.gradle:integration-test-plugin:1.5.0")
}
}
apply(plugin = "com.coditory.integration-test")
}
but it fails with:
* What went wrong:
Plugin with id 'com.coditory.integration-test' not found.
It works perfectly OK if I move apply(plugin = ...) line from init script to build.gradle.kts.
It also works if I wrap the line into `afterEvaluate`:
afterEvaluate {
apply(plugin = "com.coditory.integration-test")
}
but it's important for me to apply the plugin before buildscript evaluation.
Also, I don't want to add the plugin to init script classpath and apply it like that:
import com.coditory.gradle.integration.IntegrationTestPlugin
initscript {
dependencies {
classpath("com.coditory.gradle:integration-test-plugin:1.5.0")
}
}
rootProject {
apply<IntegrationTestPlugin>()
}
because I need to configure other plugins from my plugin. Given the above config, extensions of the other plugins will be loaded by different classloader and the only way to configure them is to use reflection.
Is it expected behavior that my first example fails? If so - is there any way to apply a plugin from init script, before the buildscript evaluation?Radosław Panuszewski
10/12/2024, 9:29 AMrootProject {
buildscript {
dependencies {
// just some random plugin, doesn't matter
classpath("com.coditory.gradle:integration-test-plugin:1.5.0")
}
}
apply(plugin = "com.coditory.integration-test")
}
fails with:
* What went wrong:
Plugin with id 'com.coditory.integration-test' not found.
Thanks in advance!Thomas Broyer
10/12/2024, 9:45 PMThomas Broyer
10/12/2024, 9:47 PMprojectLoaded (to setup the buidscript dependency), beforeProject and/or afterProject (to apply the plugin)Radosław Panuszewski
10/12/2024, 10:01 PMprojectLoaded for buildscript dependency and `beforeProject`/`afterProject` for applying the plugin doesn't work 😞
I think the latter hypothesis (about adding buildscript dependency too late) is not the case, because everything it works after moving plugin application to build.gradle.kts
The only way I've found to make it working is something like that:
rootProject {
buildscript {
dependencies {
classpath("com.coditory.gradle:integration-test-plugin:1.5.0")
}
}
pluginManager.withPlugin("base") {
apply(plugin = "pl.allegro.tech.build.init")
}
}
but I need at least one other plugin (base in the example above) to be applied explicitly by the build.gradle.kts 😕 my requirement is to apply the plugin even if no other plugins are appliedRadosław Panuszewski
10/13/2024, 7:25 PMbuildscriptClasspathAvailable { ... }, that can be used to apply imperative plugins from init script.
I've submitted a feature request for that: #30891. If this kind of change makes sense for the maintainers, I can offer a pull request 🙂