El Zhang
05/23/2021, 3:16 AM*.gradle.kts
are flexible to add/remove easily if developer wants. So I designed a arch like below diagram.
2. As we all know *.gradle.kts
files can not place in the same place as build.gradle.kts
and let build.gradle.kts
apply it if we need to apply some plugins in this *.gradle.kts
(while Groovy DSL works in this case), the common practice is move them to /buildSrc
or a composite-build module, let say /build-env
.
a. If /buildSrc
, seems it does not support include()
includeBuild()
to include plugin source modules
b. if /build-env
, I can refer plugin source via either include()
or includeBuild()
, however it does not have kotlin-dsl-accessors generated, so I can not use plugins{ id("slack")}
with slackNotifyExt{ channel = "" }
dsl extensions (but looks like apply<Plugin>() and configure<Ext>() works)
I'm wondering what is the best practice for this scenario? Below is a simple diagram to show my proposal arch.El Zhang
05/23/2021, 3:26 AM/buildSrc/settings.gradle.kts
include(":slack")
project(":slack").projectDir = file("../plugins/slack")
buildSrc/build.gradle.kts
implementation(project(":slack"))
error:
Could not determine the dependencies of task 'buildSrccompileGroovy'.
Could not resolve all task dependencies for configuration 'buildSrccompileClasspath'.> Could not resolve project buildSrcslack. Required by: project :buildSrc > No matching configuration of project buildSrcslack was found. The consumer was configured to find an API of a library compatible with Java 8, preferably not packaged as a jar, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but: - None of the consumable configurations have attributes.
Vampire
05/23/2021, 1:59 PMAs we all knowSeems your range of "we all" is much too narrow as I for example know the exact opposite. You can perfectly well putfiles can not place in the same place as*.gradle.kts
and letbuild.gradle.kts
apply it if we need to apply some plugins in thisbuild.gradle.kts
(while Groovy DSL works in this case)*.gradle.kts
*.gradle.kts
besides build.gradle.kts
and apply them as "normal" script plugins without any problems just like with Groovy DSL. You just have some restrictions, like not being able to use a plugins
block and due to that not having generated accessors available. But if you write them without the generated accessors or plugins block, they work just fine. It is just much more inconvenient than using them as pre-compiled script plugins, not only because the restricted syntax within the script plugin, but also because when it is a pre-compiled script plugin that you apply via plugins
block you also get accessors for the things the script plugin did in the build script where you apply it to.
IfThat's only to one third correct. First third:, seems it does not support/buildSrc
include()
to include plugin source modulesincludeBuild()
buildSrc
is a full standalone multi-project build, you can use include
as much as you want.
Second third: it is correct that you cannot use includeBuild
within buildSrc
Thrid third: since 6.7 buildSrc
can see builds that were included by the main build, so if you use includeBuild
in your root settings.gradle(.kts)
, then buildSrc
can see and use that included build.
ifThen you maybe did not apply the right plugin or made some other error. precompiled script plugins always get accessors generated for things applied via, I can refer plugin source via either/build-env
orinclude()
, however it does not have kotlin-dsl-accessors generated, so I can not useincludeBuild()
withplugins{ id("slack")}
dsl extensions (but looks like apply<Plugin>() and configure<Ext>() works)slackNotifyExt{ channel = "" }
plugins
block within them, no matter whether it is in buildSrc
, an included build or a standalone build.
As I said before, if you provide an MCVE where you show what does not work that you think should work, maybe we can help and tell you how to do it properly or why it does not work as expected.El Zhang
05/23/2021, 2:08 PMEl Zhang
05/24/2021, 2:08 PMEl Zhang
05/24/2021, 2:10 PM*.gradle.kts
are flexible to add/remove easily if developer wants. I basically built 2 samples to implement my thoughts, one bases on buildSrc, the other one is composite-build. I made the safe accessors work (this is one of the most important part I want, or I can basically put them in same the place as build.gradle.kts haha)Vampire
05/24/2021, 2:33 PMI would like to let u know the repo and see what can be improved.Glad that you solved your problems already, But I fear I don't have the time to "see what can be improved". If you have specific questions, sure, state them, but I'm not going to review the whole build.
Btw, is there anyway I can buy u a coffee? Very appreciate for you help 😃Totally not necessary, but if you insist, you can for example send some Coffee via PayPal: https://paypal.me/BjoernKautler 🙂
El Zhang
05/26/2021, 6:56 AMBut if you write them without the generated accessors or plugins block, they work just fine.Hi @Vampire , I have a follow-up of your previous comment. I tried to implement the plugin config script as you mentioned, but encountered some problems: 1. There are a plugin and its extension class declared in /build-env/plugin-config/src/main/kotlin 2. The
/app/build-env-config.gradle.kts
script can refer the plugin id and apply it successfully
3. However, both 2 classes(plugin&extension) are not available from the context of /app/build-env-config.gradle.kts
(can not import and configure the extension)
The MVCE can be found from below link: https://github.com/2BAB/KTS-BuildSrc-Composite/tree/main/config-gradle-kts
Thanks.Vampire
05/26/2021, 7:54 AMbuild-env-config.gradle.kts
is a normal script plugin, not a precompiled script plugin. That means it had certain limitations. One is for example that you cannot use the plugins
block, but only the legacy way of applying plugins using apply
. As a consequence you do not get any accessors, as you only get them in precompiled script plugins and only for built-in stuff and things you applied via plugins
block.
Actually I wonder that applying by id when worked if it really did. I mean to remember that applying by id does not work in normal script plugins, but only by class.
To add the classes to the class path, you need to add a buildscript block where you define the dependency if you really want to use a normal script plugin.El Zhang
05/26/2021, 8:14 AMprintln("BuildEnvStubPlugin applied.")
it did printed.
3. Just now I add the buildscript to build-env-config.gradle.kts
, though the IDE still can not detect the classes, but the build is working. (Env: IDEA 2021.1.2-rc, Gradle 7.0.2)El Zhang
05/26/2021, 8:15 AMEl Zhang
05/26/2021, 8:41 AMVampire
05/26/2021, 9:10 AMEl Zhang
05/27/2021, 9:28 AM