Slackbot
08/15/2023, 7:58 AMChris Sawczuk
08/15/2023, 7:58 AMpublishing.gradle.kts
I lose access to things like the version catalogue and I'm unable to apply plugins.
I'm importing the script by using:
apply(from = "$rootDir/publishing.gradle.kts")
Adam
08/15/2023, 8:08 AMbuildSrc/build.gradle.kts
(example, but the only important bit for you is the kotlin-dsl
plugin)
2. create buildSrc/settings.gradle.kts
(example)
3. create a convention plugin for publishing config, buildSrc/src/main/kotlin/my-publishing-config.gradle.kts
(the name will be the plugin ID, so it helps to pick a distinctive name). You can treat it like a regular build.gradle.kts
file, and apply the maven-publish
plugin, and any config you want to re-use
4. now apply the convention plugin in the plugins block of each subproject
// my-cool-subproject/build.gradle.kts
plugins {
`my-publishing-config`
}
Chris Sawczuk
08/15/2023, 8:12 AMChris Sawczuk
08/15/2023, 9:03 AMAdam
08/15/2023, 9:06 AMefemoney
08/21/2023, 7:14 PMapply false
will bring the types into the script then
• subproject { … } to configure the sub projectsAdam
08/21/2023, 9:06 PMsubprojects {}
(and allprojects {}
) is usually discouraged - see the docs here, here, and here.
What it boils down to composition vs inheritance. allprojects {}
and subprojects {}
makes Gradle configuration inherited, which in principle is fine (after all inheriting build config how Maven works, and that's a strong build tool), but generally it makes Gradle slower, harder to configure, and it's easier to make mistakes.