Publishing and reusing/applying gradle build scripts in a Jar file

We have broken down our build scripts into several smaller, purpose-specific scripts that can be applied if a project or module needs to use them. For example, if you are using Kotlin, we apply a kotlin.gradle script that sets the project up to use Kotlin; if we use Sonarqube, same story - just apply a sonarqube.gradle script.

Currently those scripts reside in a separate repository, and we use git submodule to create a local “copy” of those scripts and share them across different projects. This works; however, I’m wondering if there is a way to package those scripts in a Jar file that we publish to a repository, and then bootstrap our main script by declaring a dependency on that Jar that would make those scripts visible, so we can apply them.

Or am I smoking something pretty hard core?

You should have a look at precompiled script plugins.
Those work both with Kotlin DSL and also Groovy DSL and you can then easily publish them and use them just like regular plugins.

I’ll definitely have a look. As a workaround, I’m packaging those scripts in a jar file and adding it to the classpath, but I like your suggestion better.