Files
GseTDDUebungKCLR/build.gradle

143 lines
3.6 KiB
Groovy

plugins {
id 'java'
id 'jacoco'
id 'application'
}
group = 'hhn.temp.project'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation 'com.mysql:mysql-connector-j:9.5.0'
}
sourceSets {
main {
java {
srcDir("src")
}
}
test {
java {
srcDir("test")
}
}
}
// Test configuration
test {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
exceptionFormat "full"
showStandardStreams = true
}
// Generate test reports in a specific location
reports {
html.outputLocation.set(layout.buildDirectory.dir("reports/tests"))
junitXml.outputLocation.set(layout.buildDirectory.dir("reports/tests"))
}
finalizedBy jacocoTestReport
}
// Jacoco configuration
jacoco {
toolVersion = '0.8.13'
reportsDirectory.set(layout.buildDirectory.dir('reports/jacoco'))
}
jacocoTestReport {
dependsOn test
reports {
xml.required = true
csv.required = false
html.required = true
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
}
}
// Application configuration
application {
mainClass = "hhn.temp.project.Main"
}
// Custom task to print information after build
task printInfo {
dependsOn test, jacocoTestReport
doLast {
println("\n" + "="*50)
println("BUILD AND TESTS COMPLETED SUCCESSFULLY!")
println("="*50)
println("\nTest Results Location:")
println(" HTML: ${layout.buildDirectory.get()}/reports/tests/index.html")
println(" XML: ${layout.buildDirectory.get()}/reports/tests/TEST-*.xml")
println("\nJacoco Coverage Reports:")
println(" HTML: ${layout.buildDirectory.get()}/reports/jacoco/html/index.html")
println(" XML: ${layout.buildDirectory.get()}/reports/jacoco/test/jacocoTestReport.xml")
println("\nTo run the application:")
println(" gradle run --console=plain")
println("\nTo run tests and generate coverage reports:")
println(" gradle test jacocoTestReport")
println("="*50)
}
}
// Custom task that combines clean, test, jacocoTestReport
task cleanTestReport {
dependsOn clean, test, jacocoTestReport
description = 'Clean build and run tests with coverage reports'
group = 'verification'
}
// Configure the standard run task
run {
dependsOn test, jacocoTestReport
standardInput = System.in
doFirst {
println("\n" + "="*50)
println("TESTS COMPLETED - STARTING APPLICATION...")
println("="*50)
}
}
// Create an alias task
task cleanRun {
dependsOn clean, run
description = 'Clean build, run tests with coverage, then run the application'
group = 'application'
}
// Alternative: Create a separate task that doesn't chain dependencies
task startApp(type: JavaExec) {
description = 'Start the application (without running tests first)'
group = 'application'
classpath = sourceSets.main.runtimeClasspath
mainClass = application.mainClass
standardInput = System.in
standardOutput = System.out
// Configure to run in foreground
systemProperties System.getProperties()
doFirst {
println("\n" + "="*50)
println("STARTING APPLICATION...")
println("="*50)
}
}
// Make test and jacocoTestReport trigger the info print
test.finalizedBy printInfo