Skip to content

Releasing to Maven Central, Changelog generation, version management with conventional commits... a highly configurable shared Gradle script.


Notifications You must be signed in to change notification settings


Repository files navigation

Gradle Scripts

Maven Central

This is a gradle script, written in a highly configurable way, much like I've blogged about in Jenkins. It contains a bunch of features that I use in my Gradle projects.

Example usage can be found in:

How does it work?

It packages a jar. Uploads it to a Maven repository. Users can add the jar to their classpath and apply the main.gradle script from that jar.

The behaviour of the script is highly configurable by supplying a project.ext.buildConfig. The given config will be merged with the defaultConfig.

apply plugin: 'java-library'

buildscript {
 repositories {
 dependencies {
  classpath 'se.bjurr.gradle:gradle-scripts:2.+'
project.ext.buildConfig = [
  // Your can supply a given config here, a subset of defaultConfig.
apply from: project.buildscript.classLoader.getResource('main.gradle').toURI()


Missing something? Pull requests are welcome =)

All configuration options are documented in the defaultConfig.

def defaultConfig = [
   * "DEFAULT" - Works for most Java projects.
   * "GRADLE" - A Gradle plugin.
   * "COMMAND" - Runnable JAR, distributed in Central and NPM.
  repoType: "DEFAULT",
  sourceCompatibility: 17,
  targetCompatibility: 17,
  staticCodeAnalysis: [
    * Maximum number of violations to accept from static code analysis.
    maxViolations: 9999,
  publishing: [
    website: '' +,
    vcsUrl: '',
    licenseName: 'The Apache Software License, Version 2.0',
    licenseUrl: '',
    developerId: 'tomasbjerre',
    developerName: 'Tomas Bjerre',
    developerEmail: '',
    * If using PasswordCredentials and repository name "nexus", you will
    * need to supply username/password properties named "nexusUsername"
    * and "nexusPassword". Perhaps in ~/.gradle/
    mavenRepositoryName: "nexus",
    mavenRepositoryUrl: '',
     * true, if you want the repository in Nexus to be closed and pomoted to Release.
    nexusCloseAndRelease: true,
    * If using signing you will need to supply signing properties.
    * Perhaps in ~/.gradle/
    sign: true,
    * If not empty: creates a fat jar with relocated packages.
    * Example: [ "", "a.b:se.bjurr.a.b" ]
    * Will make up a relocation target for "" and will use "se.bjurr.a.b" as target for "a.b".
    relocate: [],
  gradlePlugin: [
    tags: []
  changelog: [
    enabled: true,
    githubTokenEnvVariableName: 'GITHUB_OAUTH2TOKEN',
    githubOrganization: 'tomasbjerre',
    jiraIssuePattern: "\\bJENKINS-([0-9]+)\\b",
    ignoreCommitsIfMessageMatches: "^\\[maven-release-plugin\\].*|^\\[Gradle Release Plugin\\].*|^Merge.*|.*\\[GRADLE SCRIPT\\].*"
  violations: [
     * Update with table of parsers and reporters.
    updateReadme: false
  manifest: [
    mainClass: ''
   * Will be configured if they exist.
  generatedSourceFolders: [
  formattingExcludedPatterns: [
   * Will be configured if they exist.
  extraTestSourceFolders: [
   * Used as "from" in jar if it exists. Can be used to do annotation processing.
  jarResourcesFolder: 'src/jar/resources'

Publishing releases

It can:

  • Step version
  • Package release
  • Sign release
  • Publish release to repository (like Nexus or Maven Central)
  • Create a changelog
  • Commit/tag/push to Git
  • Close and promote release in Nexus


./gradlew releasePatch
./gradlew releaseMinor
./gradlew releaseMajor

Or by relying on conventional commits and just doing:

./gradlew release

Static code analysis

It has Spotbugs configured in combination with Violations Gradle Plugin. Any violations will be printed nicely in the build log. And build can optionally be failed based on number of violations.

Other features

  • Automated changelog
  • Code formatting, with Google Java Format.
  • Shadowing, producing fat-jar
  • Signing artifacts with PGP
  • ...


Gradle wrapper can be downloaded with:

cat > gradle/wrapper/ << EOL

./gradlew wrapper \
 --gradle-version=8.6 \

In many cases you can just run the gradlew wrapper task. But there are cases where this does not work. On such case is if you are using Java version X and the current wrapper only support version Y, the current wrapper cannot run. Se example error below:

$ java -version

openjdk version "21.0.2" 2024-01-16
OpenJDK Runtime Environment (build 21.0.2+13-Ubuntu-122.04.1)
OpenJDK 64-Bit Server VM (build 21.0.2+13-Ubuntu-122.04.1, mixed mode, sharing)
$ ./gradlew wrapper --gradle-version=8.6 --distribution-type=bin

Downloading https://X/distributions/


FAILURE: Build failed with an exception.

* Where:
Build file 'X/build.gradle'

* What went wrong:
Could not compile build file 'X/build.gradle'.
> startup failed:
  General error during semantic analysis: Unsupported class file major version 65

  java.lang.IllegalArgumentException: Unsupported class file major version 65
        at groovyjarjarasm.asm.ClassReader.<init>(

Developer instructions

You can fiddle with the script localy by installning it with:

./gradlew publishToMavenLocal -Pversion=latest-SNAPSHOT


Releasing to Maven Central, Changelog generation, version management with conventional commits... a highly configurable shared Gradle script.