Git Product home page Git Product logo

gradle-build-info-plugin's Introduction

gradle-build-info-plugin

Build Status Build status Coverage Stagus Bintray Maven Central

Gradle plugin to include build information such as Git commit ID to your JAR.

Usage

Apply plugin:

plugins {
    id 'com.github.ksoichiro.build.info' version '0.1.5'
}

Note that you can use this plugin only when you use java plugin because you build JAR:

apply plugin: 'java'

When used with Spring Boot Actuator dependency, this plugin will also generate git.properties, which will be recognized by Spring Boot Actuator's info endpoint.

Then just build your project:

$ ./gradlew build

Now your Manifest in JAR includes special attributes:

$ unzip -p build/libs/yourJar.jar META-INF/Manifest.MF
Manifest-Version: 1.0
Git-Branch: master
Git-Commit: 154f026
Git-Committer-Date: 2015-12-17 20:05:55 +0900
Build-Date: 2015-12-17 20:15:15 +0900
Build-Java-Version: 1.8.0_45
Build-Java-Vendor: Oracle Corporation
Build-Os-Name: Mac OS X
Build-Os-Version: 10.10.1

And when Spring Boot Actuator is used with it, git.properties will be generated:

$ cat build/resources/main/git.properties
git.branch=master
git.commit.id=38a0c0c
git.commit.time=2015-12-16 23\:40\:13 +0900

Configuration

You can configure this plugin with buildInfo extension in build.gradle:

buildInfo {
    // Date format string used to Git committer date.
    committerDateFormat 'yyyy-MM-dd HH:mm:ss Z'

    // Date format string used to build date.
    buildDateFormat 'yyyy-MM-dd HH:mm:ss Z'

    // Set to true if you want to generate/merge Manifest.MF.
    manifestEnabled true

    // Set to true if you want to generate git.properties.
    // Default is false, but when you use Spring Boot Actuator
    // and you don't set this property explicitly to false,
    // git.properties will be generated.
    gitPropertiesEnabled false

    // Behavior when the plugin cannot read .git directory.
    // Set to MODE_IGNORE if you want to ignore it and proceed task.
    // Set to MODE_ERROR if you want to throw an exception to stop build.
    // Default is MODE_DEFAULT.
    // MODE_DEFAULT will set the values of branch, commit,
    // and committer date to "unknown", then proceed task.
    gitInfoMode com.github.ksoichiro.build.info.BuildInfoExtension.MODE_DEFAULT

    // Set to false if you want to suppress log when .git directory
    // cannot be read.
    // Default is true.
    warnIfGitDirectoryIsMissing false

    // Set to false if you want to exclude some attributes
    // from the manifest file.
    // All properties are true by default.
    attributeGitBranchEnabled false
    attributeGitCommitEnabled false
    attributeGitCommitterDateEnabled false
    attributeBuildDateEnabled false
    attributeBuildJavaVersionEnabled false
    attributeBuildJavaVendorEnabled false
    attributeBuildOsNameEnabled false
    attributeBuildOsVersionEnabled false
}

License

Copyright 2015 Soichiro Kashima

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

gradle-build-info-plugin's People

Contributors

ksoichiro avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.