• Stars
    star
    865
  • Rank 52,730 (Top 2 %)
  • Language
    Groovy
  • License
    MIT License
  • Created about 12 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

gradle-release is a plugin for providing a Maven-like release process for projects using Gradle

gradle-release plugin

Build Status Gradle Plugin page

Introduction

The gradle-release plugin is designed to work similar to the Maven release plugin. The gradle release task defines the following as the default release process:

  • The plugin checks for any un-committed files (Added, modified, removed, or un-versioned).
  • Checks for any incoming or outgoing changes.
  • Checkout to the release branch and merge from the working branch (optional, for GIT only, with pushReleaseVersionBranch)
  • Removes the SNAPSHOT flag on your project's version (If used)
  • Prompts you for the release version.
  • Checks if your project is using any SNAPSHOT dependencies
  • Will build your project.
  • Commits the project if SNAPSHOT was being used.
  • Creates a release tag with the current version.
  • Checkout to the working branch (optional, for GIT only, with pushReleaseVersionBranch)
  • Prompts you for the next version.
  • Commits the project with the new version.

Current SCM support: Bazaar, Git (1.7.2 or newer), Mercurial, and Subversion

Installation

The gradle-release plugin will work with Gradle 6.0 and beyond

Legacy plugin application

buildscript {
  repositories {
    maven {
      url 'https://plugins.gradle.org/m2/'
    }
  }
  dependencies {
    classpath 'net.researchgate:gradle-release:3.0.2'
  }
}

apply plugin: 'net.researchgate.release'

Plugin DSL

plugins {
  id 'net.researchgate.release' version '3.0.2'
}

Please refer to the Gradle DSL PluginDependenciesSpec to understand the behavior and limitations when using the new syntax to declare plugin dependencies.

Usage

After you have your build.gradle file configured, simply run: gradle release and follow the on-screen instructions.

Configuration

As described above, the plugin will check for un-committed files and SNAPSHOT dependencies. By default the plugin will fail when any un-committed, or SNAPSHOT dependencies are found.

Below are some properties of the Release Plugin Convention that can be used to make your release process more lenient

Name Default value Description
failOnCommitNeeded true Fail the release process when there are un-committed changes. Will commit files automatically if set to false.
failOnPublishNeeded true Fail when there are local commits that haven't been published upstream (DVCS support)
failOnSnapshotDependencies true Fail when the project has dependencies on SNAPSHOT versions unless those SNAPSHOT dependencies have been defined as 'ignoredSnapshotDependencies' using the syntax '$group:$name'
failOnUnversionedFiles true Fail when files are found that are not under version control
failOnUpdateNeeded true Fail when the source needs to be updated, or there are changes available upstream that haven't been pulled
revertOnFail true When a failure occurs should the plugin revert it's changes to gradle.properties?
pushReleaseVersionBranch null (GIT only) If set to the name of a branch, the `release` task will commit the release on this branch, and the next version on the working branch.

Below are some properties of the Release Plugin Convention that can be used to customize the build

Name Default value Description
tagTemplate $version The string template which is used to generate the tag name. Possible variables are $version and $name. Example: '$name-$version' will result in "myproject-1.1.0". (Always ensure to use single-quotes, otherwise `$` is interpreted already in your build script)
preCommitText This will be prepended to all commits done by the plugin. A good place for code review, or ticket numbers
preTagCommitMessage [Gradle Release Plugin] - pre tag commit: The commit message used to commit the non-SNAPSHOT version if SNAPSHOT was used
tagCommitMessage [Gradle Release Plugin] - creating tag: The commit message used when creating the tag. Not used with BZR projects
newVersionCommitMessage [Gradle Release Plugin] - new version commit: The commit message used when committing the next version
snapshotSuffix -SNAPSHOT The version suffix used by the project's version (If used)

Below are some properties of the Release Plugin Convention that are specific to version control.

VCS Name Default value Description
Git requireBranch main Defines the branch which releases must be done off of. Eg. set to `release` to require releases are done on the `release` branch (or use a regular expression to allow releases from multiple branches, e.g. `/release|main/`). Set to empty string "" to ignore.
Git commitOptions {empty} Defines an array of options to add to the git adapter during a commit. Example `commitOptions = ["-s"]`
Git pushOptions {empty} Defines an array of options to add to the git adapter during a push. This could be useful to have the vc hooks skipped during a release. Example `pushOptions = ["--no-verify"]`
Git signTag false Adds `-s` parameter to the tag command

To set any of these properties to false, add a "release" configuration to your project's build.gradle file. Eg. To ignore un-versioned files, you would add the following to your build.gradle file:

release {
  failOnUnversionedFiles = false
}

Eg. To ignore upstream changes, change 'failOnUpdateNeeded' to false:

release {
  failOnUpdateNeeded = false
}

This are all possible configuration options and its default values:

release {
    failOnCommitNeeded = true
    failOnPublishNeeded = true
    failOnSnapshotDependencies = true
    failOnUnversionedFiles = true
    failOnUpdateNeeded = true
    revertOnFail = true
    preCommitText = ''
    preTagCommitMessage = '[Gradle Release Plugin] - pre tag commit: '
    tagCommitMessage = '[Gradle Release Plugin] - creating tag: '
    newVersionCommitMessage = '[Gradle Release Plugin] - new version commit: '
    tagTemplate = '${version}'
    versionPropertyFile = 'gradle.properties'
    versionProperties = []
    snapshotSuffix = '-SNAPSHOT'
    buildTasks = []
    ignoredSnapshotDependencies = []
    versionPatterns = [
        /(\d+)([^\d]*$)/: { Matcher m, Project p -> m.replaceAll("${(m[0][1] as int) + 1}${m[0][2]}") }
    ]
    pushReleaseVersionBranch = null
    scmAdapters = [
        net.researchgate.release.GitAdapter,
        net.researchgate.release.SvnAdapter,
        net.researchgate.release.HgAdapter,
        net.researchgate.release.BzrAdapter
    ]

    git {
        requireBranch.set('main')
        pushToRemote.set('origin')
        pushToBranchPrefix.set('')
        commitVersionFileOnly.set(false)
        signTag.set(false)
    }

    svn {
        username.set(null)
        password.set(null)
        pinExternals.set(false)   // allows to pin the externals when tagging, requires subversion client >= 1.9.0
    }
}

Kotlin DSL Example

import net.researchgate.release.ReleaseExtension
repositories {
    maven {
      url 'https://plugins.gradle.org/m2/'
    }
  }
  dependencies {
    classpath 'net.researchgate:gradle-release:3.0.2'
  }

apply(plugin = "base")
apply(plugin = "net.researchgate.release")

configure<ReleaseExtension> {
    ignoredSnapshotDependencies.set(listOf("net.researchgate:gradle-release"))
    with(git) {
        requireBranch.set("master")
        // to disable branch verification: requireBranch.set(null as String?)
    }
}

Custom release steps

To add a step to the release process is very easy. Gradle provides a very nice mechanism for manipulating existing tasks. There are two available hooks provided: beforeReleaseBuild which runs before build and afterReleaseBuild which runs afterwards.

For example, if we wanted to make sure uploadArchives is called and succeeds after the build with the release version has finished, we would just add the uploadArchives task as a dependency of the afterReleaseBuild task:

afterReleaseBuild.dependsOn uploadArchives

Multi-Project Builds

Support for multi-project builds isn't complete, but will work given some assumptions. The gradle-release plugin assumes and expects that only one version control system is used by both root and sub projects.

Apply the plugin separately to each subproject that you wish to release. Release using a qualified task name, e.g.:

./gradlew :sub:release # release a subproject named "sub"
./gradlew :release # release the root project

Working in Continuous Integration

In a continuous integration environment like Jenkins or Hudson, you don't want to have an interactive release process. To avoid having to enter any information manually during the process, you can tell the plugin to automatically set and update the version number.

You can do this by setting the release.useAutomaticVersion property on the command line, or in Jenkins when you execute gradle. The version to release and the next version can be optionally defined using the properties release.releaseVersion and release.newVersion.

gradle release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=1.0.0 -Prelease.newVersion=1.1.0-SNAPSHOT

Getting Help

To ask questions please use stackoverflow or github issues.

To report bugs, please use the GitHub project.

More Repositories

1

react-intersection-observer

React component for the Intersection <Observer /> API
JavaScript
1,125
star
2

react-intersection-list

React infinite scroll using the Intersection <Observer /> API
JavaScript
141
star
3

broker

A full proxy for composer repositories
PHP
119
star
4

webpack-watchman-plugin

A webpack plugin that integrates watchman as its watcher.
JavaScript
55
star
5

phpnsc

Small tool to check for missing use statements when using PHP namespaces
PHP
43
star
6

react-fast-highlight

A fast react component wrapper for highlight.js
TypeScript
40
star
7

injektor

Dependency injection container for PHP, inspired by google-guice
PHP
38
star
8

avro-php

Generic Apache Avro PHP available as a composer package
PHP
38
star
9

azkaban-ldap-usermanager

Ldap authentication for Azkaban
Java
24
star
10

path-chunk-webpack-plugin

[Deprecated] Plugin to create a chunk based on matching against the module path.
JavaScript
22
star
11

spire

๐Ÿ—ผExtensible JavaScript toolbox management
JavaScript
22
star
12

gemini-react

Plugin, which simplifies writing gemini tests for react components
JavaScript
22
star
13

inline-stylesheet

Create inline styles for your components
JavaScript
21
star
14

restler

Restler is a project aiming on providing a unified way to easily build REST-services based on document-oriented databases, like MongoDB.
Java
16
star
15

moment-shortformat

moment-shortformat.js is an extension to moment.js that formats dates in a short format like it's used on ResearchGate.
JavaScript
16
star
16

gradle-release-examples

Repository containing all kinds of different configuration possibilities for the gradle-release plugin
Java
12
star
17

node-file-processor

Node.js utility for mass-processing files in parallel.
JavaScript
10
star
18

grunt-changed

Configure Grunt tasks to run with changed file contents only
JavaScript
10
star
19

babel-plugin-transform-scss-import-to-string

Babel plugin for inlining Sass imports into transpiled strings
JavaScript
10
star
20

babel-plugin-react-class-display-name

Add displayName to ES6 classes that extend React.Component
JavaScript
9
star
21

emailonacid

โœ‰๏ธ Mail visual regression testing library based on Email on Acid API
JavaScript
8
star
22

tooling

๐Ÿ›  ResearchGate's JavaScript Tooling
JavaScript
7
star
23

node-package-blueprint

Blueprint for scaffolding new node packages
JavaScript
7
star
24

rosalind-serif

Rosalind Serif โ€“ย A serif typeface built for ResearchGate
7
star
25

nodejs-simple-downloader

A simple cli downloader for nodejs
Go
5
star
26

mongoose-avro-schema-generator

Generates Apache avro schemas from mongoose schemas.
JavaScript
5
star
27

archaius-consul

Consul Connector for Archaius
Java
5
star
28

typewriter

PHP
4
star
29

CodingDojo

CodingDojo for Berlin organized at ResearchGate
Python
4
star
30

kafka-metamorph

Apache Kafka consumer API for selective partition consumption and explicit offset control
Java
3
star
31

doctrine-file

File-Reader for the Doctrine JSDoc Parser
JavaScript
3
star
32

foreman-templates

HTML
2
star
33

babel-preset-rg

Moved to https://github.com/researchgate/tooling
JavaScript
2
star
34

linting

Moved to https://github.com/researchgate/tooling
JavaScript
2
star
35

gemini-babel

Gemini plugin, which allows to use babel for writing tests.
JavaScript
2
star
36

babel-plugin-transform-react-jsx-props

Add additional props to a jsx snippet
JavaScript
1
star
37

gemini-localip

Gemini plugin to dynamically set root url to local ip address
JavaScript
1
star
38

diamond-linkerd-collector

Python
1
star
39

webpack-plugin-flow

Runs flow check before webpack compile or watch
JavaScript
1
star
40

logstash_gelfamqp_plugin

A logstash output plugin converts a logstash message to a GELF message that can be consumed by graylog2 and then pushes them to an amqp exchange.
Ruby
1
star