Skip to content

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

Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Gradle Scripts

Build Status 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'

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.
  repoType: "DEFAULT",
  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: [
   * 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
  • ...


Tested with Gradle 7.0.2.

./gradlew wrapper --gradle-version=6.8.3 --distribution-type=bin

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.




Sponsor this project