Skip to content

Instantly share code, notes, and snippets.

@darrylanderson
Created May 17, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrylanderson/463cef19ca2037280ef5601e508b67e0 to your computer and use it in GitHub Desktop.
Save darrylanderson/463cef19ca2037280ef5601e508b67e0 to your computer and use it in GitHub Desktop.
buildscript {
repositories {
jcenter()
}
dependencies {
// The gradle-docker plugin we want to use isn't yet in gradle plugin portal, se we
// pull it from jcenter
classpath 'se.transmode.gradle:gradle-docker:1.2'
}
}
plugins {
// Use the Spring Boot Gradle plugin, which automatically applies the dependency management plugin
// and configures it to import the spring-boot-starter-parent bom.
id 'org.springframework.boot' version '1.5.10.RELEASE'
// Versioning plugin
id 'pl.allegro.tech.build.axion-release' version '1.8.1'
}
// The Java plugin allows us to compile and package our code into a jar file
apply plugin: 'java'
// Support for packaging our application as a Docker image
apply plugin: 'docker'
// Define the namespace for our build artifacts (replace with your own group)
group 'atc'
// Explicitly declare that we're using JDK 1.8
sourceCompatibility = 1.8
// Use Maven Central to resolve all 3rd party dependencies
repositories {
mavenCentral()
}
// Using the dependency management plugin, import the dependencies for
// Spring Cloud release train 'Edgware.SR2'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Edgware.SR2'
}
}
dependencies {
// Enable Spring MVC
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web'
// Enable Spring Security
compile group: 'org.springframework.boot', name: 'spring-boot-starter-security'
// Production metrics for Spring Boot
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator'
// Service registration via Eureka
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-eureka-server'
// Enable distributed tracing with Sleuth
compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-zipkin'
// Enable JSON logging
runtime( group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '4.11' ) {
exclude group: 'ch.qos.logback', module: 'logback-core'
}
testCompile group: 'junit', name: 'junit', version: '4.12'
}
// Configure the spring boot executable jar
springBoot {
executable = true
buildInfo()
}
// Versioning with the Axion release plugin
scmVersion {
// Treat uncommitted changes as trigger for version increment
ignoreUncommittedChanges = false
// All versions will start with "v"
tag {
prefix = 'v'
versionSeparator = ''
}
// Our versioning scheme is major.minor.rcX. If we're on a branch named "release/*", increment the release
// candidate number, otherwise increment the minor version number.
versionIncrementer 'incrementMinorIfNotOnRelease', [releaseBranchPattern: 'release.*']
branchVersionIncrementer = [
'master' : 'incrementMinor',
'feature' : 'incrementMinor',
'release/.*': 'incrementPrerelease'
]
// Decorators
versionCreator 'simple'
branchVersionCreator = [
'feature/.*': 'versionWithBranch'
]
checks {
// Allow for releasing a new version if there are uncommitted changes
uncommittedChanges = false
}
}
project.version = scmVersion.version
// Add the version number to the manifest
jar {
manifest {
attributes( "Implementation-Title": project.name,
"Implementation-Version": project.version.toString() )
}
}
// Build the docker container for this application
task buildDocker( type: Docker, dependsOn: build ) {
push = false
applicationName = rootProject.name
dockerfile = file( 'Dockerfile' )
doFirst {
// Rename the app jar to "app.jar" so that the Dockerfile does not require renames
copy {
from "${project.buildDir}/libs"
into stageDir
include "${rootProject.name}-${version}.jar"
rename( "${rootProject.name}-${version}.jar", "app.jar" )
}
}
}
// Configure the Gradle wrapper
task wrapper( type: Wrapper ) {
gradleVersion = '4.5.1'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment