title: How to centralize Gradle build settings?
body: <p>Say I'm using the <a href="https://github.com/palantir/gradle-git-version" rel="nofollow noreferrer">palantir/gradle-git-version</a> Gradle plugin, and have the following code in <code>build.gradle.kts</code> to determine the project version:</p>
  <pre><code>// If release branch, return after incrementing patch version.
  // Else, return $lastTag-SNAPSHOT.
  val projectVersion: String by lazy {
      val versionDetails: groovy.lang.Closure&lt;VersionDetails&gt; by extra
      with(versionDetails()) {
          if (!lastTag.matches(&quot;^(?:(?:\\d+\\.){2}\\d+)\$&quot;.toRegex())) {
              throw GradleException(&quot;Tag '$lastTag' doesn't match 'MAJOR.MINOR.PATCH' format&quot;)
          }
          // If it detached state, get branch name from GitLab CI env var
          val branch = branchName ?: System.getenv(&quot;CI_COMMIT_REF_NAME&quot;)
          if (branch?.startsWith(&quot;release/&quot;) == true) {
              val tokens = lastTag.split('.')
              &quot;${tokens[0]}.${tokens[1]}.${tokens[2].toInt() + commitDistance}&quot;
          } else &quot;$lastTag-SNAPSHOT&quot;
      }
  }
  </code></pre>
  <p>This works, but the code is duplicated across all the projects, which is difficult to maintain except for a very small number of projects.</p>
  <p>This is just one example, the same applies for other Gradle tasks that assume certain conventions within the company/team, like creating a <code>Dockerfile</code>.</p>
  <p>What is a good way to centralize such code so that all projects can use them? Note that code like this don't usually stand on their own, but rely on Gradle plugins.</p>