gradle-build-info-plugin

Gradle plugin to include build information to your JAR

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.github.ksoichiro
ArtifactId

ArtifactId

gradle-build-info-plugin
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

gradle-build-info-plugin
Gradle plugin to include build information to your JAR
Project URL

Project URL

https://github.com/ksoichiro/gradle-build-info-plugin
Source Code Management

Source Code Management

https://github.com/ksoichiro/gradle-build-info-plugin

Download gradle-build-info-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.ksoichiro/gradle-build-info-plugin/ -->
<dependency>
    <groupId>com.github.ksoichiro</groupId>
    <artifactId>gradle-build-info-plugin</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.ksoichiro/gradle-build-info-plugin/
implementation 'com.github.ksoichiro:gradle-build-info-plugin:0.2.0'
// https://jarcasting.com/artifacts/com.github.ksoichiro/gradle-build-info-plugin/
implementation ("com.github.ksoichiro:gradle-build-info-plugin:0.2.0")
'com.github.ksoichiro:gradle-build-info-plugin:jar:0.2.0'
<dependency org="com.github.ksoichiro" name="gradle-build-info-plugin" rev="0.2.0">
  <artifact name="gradle-build-info-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.ksoichiro', module='gradle-build-info-plugin', version='0.2.0')
)
libraryDependencies += "com.github.ksoichiro" % "gradle-build-info-plugin" % "0.2.0"
[com.github.ksoichiro/gradle-build-info-plugin "0.2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.ajoberstar : grgit jar 1.4.1

test (2)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.0-groovy-2.4
org.springframework.boot : spring-boot-starter-actuator jar 1.3.0.RELEASE

Project Modules

There are no modules declared in this project.

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.2.0'
}

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.

Versions

Version
0.2.0
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0