Slackbot
10/30/2023, 2:27 PMVampire
10/30/2023, 2:52 PMext or extra is actually hacky and most often a work-around for not doing things properly.
And also any usage of legacy script plugins (the things you use with "apply from" is a smell and should not be used.
The idiomatic and recommended way to centralize and reuse build logic is to use convention plugins in buildSrc or an included build like gradle/build-logic/, for example implemented as precompiled script plugins.Aleksander
10/30/2023, 2:59 PMbuild.gradle.kts that's getting rather large.
Is it not possible to just wrap some code in a function, put it in another .kts file, and import it into build.gradle.kts ?Vampire
10/30/2023, 3:18 PMVampire
10/30/2023, 3:20 PMextra properties, this is not possible.
But using convention plugins is much cleaner and more maintainable and does not really have much overhead.Adam
10/30/2023, 6:04 PM.kt file in buildSrc and import it https://stackoverflow.com/questions/70670733/how-to-extend-the-gradle-kotlin-dsl-with-custom-extension-functions/71594449#71594449Vampire
10/30/2023, 7:54 PMAleksander
10/31/2023, 11:17 AM<project-root>/buildSrc/src/main/kotlin/somepackage/EnvVarChecker.kt with a function in it, which I'd like to call from build.gradle.kts.
At the top of build.gradle.kts, I import somepackage.EnvVarChecker, and IntelliJ successfully finds the package and offers navigation, auto-complete etc. So IntelliJ gets it.
But when I gradle build, I get build.gradle.kts:2:8: Unresolved reference: somepackage.
So Gradle itself does not seem to "see" the package inside buildSrc.
Any ideas?Aleksander
10/31/2023, 11:19 AMbuild.gradle.kts in the picture is empty. The docs said buildSrc should have a file with that name in order to be recognized.Vampire
10/31/2023, 11:35 AMbuildSrc should just have java-library and groovy plugins applied by default. But I wonder that IntelliJ shows them as sources then. Maybe a bug.Aleksander
10/31/2023, 11:38 AMbuildSrc/src/main/kotlin as "Sources root", which is why it provided autocomplete/navigation.
I unmarked it as such, now IntelliJ also has no idea what EnvVarChecker is. Yay, I guess?Adam
10/31/2023, 7:19 PMbuildSrc/build.gradle.kts?
Try adding
plugins {
`kotlin-dsl`
}
(but don't apply other Kotlin plugins, like kotlin("jvm") - Gradle might get confused)Vampire
10/31/2023, 9:53 PMembeddedKotlin("jvm") should be fine as long as no precompiled script plugins are wanted.Vampire
10/31/2023, 9:53 PMkotlin-dsl