Skip to content

Instantly share code, notes, and snippets.

@eyalgo
Created November 29, 2018 14:24
Show Gist options
  • Save eyalgo/f0e8e5c9721adc172529cc3fdc346429 to your computer and use it in GitHub Desktop.
Save eyalgo/f0e8e5c9721adc172529cc3fdc346429 to your computer and use it in GitHub Desktop.
Gradle template for spring boot. Showing how to use integration tests as well
buildscript {
ext {
springBootVersion = '2.1.0.RELEASE'
springDataVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath 'org.ajoberstar:gradle-git:1.7.2'
classpath 'org.owasp:dependency-check-gradle:3.+'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0'
classpath('org.unbroken-dome.gradle-plugins:gradle-testsets-plugin:1.2.0')
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'
apply plugin: 'checkstyle'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'findbugs'
apply plugin: 'jacoco'
apply plugin: 'org.owasp.dependencycheck'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'org.unbroken-dome.test-sets'
group = ‘my.group’
sourceCompatibility = 1.8
targetCompatibility = 1.8
mainClassName = ‘my.group.Application'
applicationName = ‘nice-app-name’
bootJar {
baseName = 'nice-app-name'
}
repositories {
mavenCentral()
jcenter()
}
testSets {
integrationTest {
dirName = 'integration-test'
}
}
dependencies {
compile(
'com.google.code.gson:gson:2.8.5',
'com.squareup.okhttp3:okhttp:3.11.0',
'com.datadoghq:java-dogstatsd-client:2.4',
'commons-io:commons-io:2.6',
'net.logstash.logback:logstash-logback-encoder:5.+',
'org.projectlombok:lombok:1.18.4',
'org.springframework.boot:spring-boot-configuration-processor',
'org.springframework.boot:spring-boot-starter-actuator',
'org.springframework.boot:spring-boot-starter-data-cassandra',
'org.springframework.boot:spring-boot-starter-integration',
'org.springframework.boot:spring-boot-starter-web',
)
testCompile(
'com.google.guava:guava:27.0-jre',
'org.springframework.boot:spring-boot-starter-test',
'uk.org.lidalia:slf4j-test:1.1.0',
)
integrationTestCompile(
'org.cassandraunit:cassandra-unit-spring:3.5.0.1',
'org.cassandraunit:cassandra-unit-shaded:3.5.0.1',
)
}
configurations.integrationTestCompile {
exclude group: 'uk.org.lidalia'
}
compileJava.dependsOn(processResources)
// JaCoCo Configuration
jacoco {
toolVersion = "0.8.1"
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/jacocoHtml")
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it,
exclude: ['**/model/**',
'**/model/**',
'**/config/**',
'**/constants/**',
'**/Webepository.class',
'**/Application.class'])
})
}
}
test {
description "Runs all unit tests"
include "**/*Test.class"
maxParallelForks = 4
mustRunAfter 'precheck'
}
task testIntegration(type: Test) {
description "Runs all integration tests"
# probably need to fix here something
group = 'verification'
testClassesDirs = sourceSets.integrationTest.output.classesDirs
classpath = sourceSets.integrationTest.runtimeClasspath
mustRunAfter 'test'
// testLogging {
// showStandardStreams = true
// }
}
task precheck {
dependsOn 'checkstyleMain'
dependsOn 'checkstyleTest'
dependsOn 'findbugsMain'
dependsOn 'findbugsTest'
}
task precommit {
dependsOn 'precheck'
dependsOn 'check'
dependsOn 'test'
dependsOn 'testIntegration'
}
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'PACKAGE'
excludes = [
‘package.model',
‘package.model.*' ]
limit {
counter = 'BRANCH'
minimum = 0.7
}
}
}
}
checkstyle {
toolVersion = '8.11'
ignoreFailures = false
configFile = file("${project.projectDir}/checkstyle/google_checks.xml")
configProperties = ['basedir': "${project.projectDir}/checkstyle/"]
}
findbugs {
toolVersion = "3.0.1"
ignoreFailures = false
reportsDir = file("${project.buildDir}/findbugsReports")
effort = "max"
reportLevel = "high"
}
tasks.withType(FindBugs) {
reports {
xml.enabled = false
html.enabled = true
}
}
distributions {
main {
baseName = "${applicationName}"
}
}
test.onlyIf { !Boolean.getBoolean('skip.tests') }
testIntegration.onlyIf { !Boolean.getBoolean('skip.tests') }
checkstyleMain.onlyIf { !Boolean.getBoolean('skip.tests') }
checkstyleTest.onlyIf { !Boolean.getBoolean('skip.tests') }
check.dependsOn testIntegration
//test.finalizedBy jacocoTestReport
//check.dependsOn jacocoTestReport
//check.dependsOn jacocoTestCoverageVerification
//jacocoTestCoverageVerification.mustRunAfter jacocoTestReport
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment