Slackbot
09/21/2023, 1:34 PMSam Edwards
09/21/2023, 1:40 PMbuildSrc
is no longer a recommended way to do that. It's non-standard and not compatible with incremental builds. Please use version catalogs. TL;DR - It's a file that lives in gradle/libs.versions.toml
and centrally declares your dependencies.
Version Catalogs: https://docs.gradle.org/current/userguide/platforms.htmlSam Edwards
09/21/2023, 1:41 PMconvention plugins
, but for only 3 modules it is probably overkill.
Convention Plugins: https://docs.gradle.org/current/samples/sample_convention_plugins.htmlmelix
09/21/2023, 1:51 PMSam Edwards
09/21/2023, 1:53 PMVampire
09/21/2023, 1:55 PMVampire
09/21/2023, 1:56 PMVampire
09/21/2023, 1:56 PMmelix
09/21/2023, 2:01 PMAli E.
09/22/2023, 7:26 AMAli E.
09/22/2023, 7:31 AMSam Edwards
09/22/2023, 12:44 PMVampire
09/22/2023, 3:06 PMwhere can I read this to not use the Spring dependency management plugin? Thankhttps://linen.dev/s/gradle-community/t/2579116/what-is-the-proper-way-to-apply-a-bom-in-a-library-project-i#a7d4a60a-ab60-48dc-8477-f3f4462d1e6a
I would still use the buildSrc which was not recommended like @Sam Edwards says?That was a misinterpretation. What he meant was, that it is not recommended to use some
Versions
class or similar to centrally manage versions in buildSrc
,
but instead you should use a version catalog for that.
Using convention plugins in buildSrc
or - what I prefer - in an included build is still the proper way to centralize and organize build logic.
Is there an example project for this other than here?There are many. For example https://github.com/jjohannes/idiomatic-gradle, but that is pretty sophisticated, and probably indeed a bit more than you should use in a smaller project, but still interesting to look at and learn from.
Maybe with Java and Kotlin support, because the modules could be either java or kotlin modules.You will simply have a convention plugin for java projects and one for kotlin projects. If there are common things, you maybe have another one with the common things that is then applied by the other two, ...
Sam Edwards
09/22/2023, 4:35 PMbuildSrc
because on larger projects you can precompile them and us binaries, but it's the same thing to use either if you don't have that need. I also just like the clean separation.Vampire
09/22/2023, 4:47 PMbuildSrc
was made a bit more like an included build like not always running tests and so on. But there are still significant differences. buildSrc
is always built and prefixed to the build script class path, overwriting any versions and changing class path of all projects and thus making things out-of-date. An included build is only built if actually used, and it is a normal dependency that is conflict resolved with other things in the same build script class path. And if you devide the build logic into multiple projects, they produce different jars, so just invalidate projects where they are actually used, not always the whole build, and so on.
For small builds this is most probably all neglectable, but in bigger builds with many different projects that need different of the build logic plugins, this can indeed become a topic.Ali E.
09/25/2023, 12:29 PMβββ api
β βββ src
β β βββ...
β βββ build.gradle.kts
βββ buildSrc
β βββ src
β β βββmain
β β βββkotlin
| | βββcommon-convention.gradle.kts
| | βββspring-convention.gradle.kts
β βββ build.gradle.kts
β βββ settings.gradle.kts
βββ domain-model
β βββ src
β β βββ...
β βββ build.gradle.kts
βββ integration-service
β βββ src
β β βββ...
β βββ build.gradle.kts
βββ settings.gradle.kts
β’ The first problem, I am trying to add detekt as a plugin and dependency in my common-convention.gradle.kts
, for this I have added the following dependency in my build.gradle.kts
: implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.23.1")
. In the common-convention.gradle.kts
I've added the following.
// common-convention.gradle.kts
plugins {
kotlin("jvm")
id("io.gitlab.arturbosch.detekt")
}
java {
sourceCompatibility = JavaVersion.VERSION_17
}
repositories {
mavenCentral()
}
detekt {
buildUponDefaultConfig = true // preconfigure defaults
allRules = true // activate all available (even unstable) rules.
}
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting")
runtimeOnly("io.github.microutils:kotlin-logging-jvm:3.0.5")
}
Then I've added the common conventions in api subproject as plugin with it's id.
When I run detekt it throw the following error:
> Could not resolve all files for configuration ':api:detektPlugins'.
> Could not find io.gitlab.arturbosch.detekt:detekt-formatting:.
Required by:
project :api
I've analyzed the dependencies and in the api module, all detekt dependencies are included, but I can not run the plugin. Any idea why?
β’ Another thing is, like you see above I've io.github.microutils:kotlin-logging-jvm:3.0.5
as dependency in the common conventions. What I did is adding this dependency in the version catalog in the setting.gradle.kts, but I cann not access this lib, only in the build.gradle.kts. Is there a proper way to do that?
β’ Last but not least, I'm getting this kind of error Argument for @NotNull parameter 'buildSrcModuleNode' of org/jetbrains/plugins/gradle/service/project/GradleBuildSrcProjectsResolver.addBuildSrcToBuildScriptClasspathData must not be null
Where I've no clue why it shows up, and that only sometimes after reload project.
Thanks in advance!!Vampire
09/25/2023, 12:34 PMio.gitlab.arturbosch.detekt:detekt-formatting
for detektPlugins
but you did not specify a versionVampire
09/25/2023, 12:36 PMWhat I did is adding this dependency in the version catalog in the setting.gradle.kts, but I cann not access this lib, only in the build.gradle.kts. Is there a proper way to do that?Within convention plugins, only with the hack-around I documented in https://github.com/gradle/gradle/issues/15383 or by using the type-unsafe string-y API instead of the accessors.
Vampire
09/25/2023, 12:42 PMLast but not least, I'm getting this kind of errorMaybe a stack trace would help, but judging by the package, this seems to be a problem in the IntelliJ Gradle integration, so you should maybe open an issue about it in JetBrains' YouTrack, or update your IDE if you are not on latest version.Argument for @NotNull parameter 'buildSrcModuleNode' of org/jetbrains/plugins/gradle/service/project/GradleBuildSrcProjectsResolver.addBuildSrcToBuildScriptClasspathData must not be null
Ali E.
09/25/2023, 1:46 PM