Hello, I have a dozen+ kotlin micro services across different git repos. Each service has its own `g...
t
Hello, I have a dozen+ kotlin micro services across different git repos. Each service has its own
gradle.build.kts
file and the duplication is driving us crazy! To start I'd like to extract common dependencies + versions and so we are looking at gradle's version catalogues. But now that we've gone down this route, there are lots of other common blocks in our
gradle.build.kts
that we'd like to capture centrally as well for example the plugins block or settings like
tasks.withType<KotlinCompile>.kotlinOptions { freeCompilerArgs = freeCompilerArgs + "-Xopt-in=kotlin.RequiresOptIn" }
. So what does best practice look like here? 🙏
👌 1
m
Usually, convention plugins are the recommended route: https://docs.gradle.org/current/samples/sample_convention_plugins.html
t
for different git repos I would probably go with custom internal Gradle plugin
t
is that difficult to create?
t
depends on your Gradle knowledge 😅
😂 1
☝️ 2
t
Wrt convention plugins, thanks for the link. From the sample project it looks like a everything is contained within one repo, is it striaghtforward to move the buildSrc folder elsewhere so ti can be referenced/imported by all of our projects
j
you can publish easily convention plugins and version catalogs
t
ah, didn't know it is possible to publish convention plugin as well: https://docs.gradle.org/current/samples/sample_publishing_convention_plugins.html
t
okay cool
these look exactly like what we need to do
🙏
j
you can publish both, normal convention plugins and settings convention plugins
v
A convention plugin is imho just a conventional name for plugins where you express your own conventions that you then apply to your projects. They could be written any way, as precompiled script plugins which is most common, or also as plain old standard plugins coded in Java or any other language. And all of these can also be published without problem.
And if you wouldn't want to publish, you could as well use something like git submodules or whatever to check out the plugins repository with your other projects repositories and use composite build to include them.
e
I moved my projects into a single repo, made development much smoother 😛