Changed the build.gradle to have an automatic build script, added the README
This commit is contained in:
104
build.gradle
104
build.gradle
@@ -18,11 +18,6 @@ dependencies {
|
||||
implementation 'com.mysql:mysql-connector-j:9.5.0'
|
||||
}
|
||||
|
||||
jacoco {
|
||||
toolVersion = '0.8.13'
|
||||
reportsDirectory.set(layout.buildDirectory.dir('customJacocoReportDir'))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
java {
|
||||
@@ -36,6 +31,7 @@ sourceSets {
|
||||
}
|
||||
}
|
||||
|
||||
// Test configuration
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
@@ -43,19 +39,105 @@ test {
|
||||
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 = false
|
||||
xml.required = true
|
||||
csv.required = false
|
||||
html.outputLocation.set(layout.buildDirectory.dir('jacocoHtml'))
|
||||
html.required = true
|
||||
html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
|
||||
}
|
||||
}
|
||||
jacocoTestCoverageVerification {
|
||||
dependsOn test
|
||||
}
|
||||
|
||||
// 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
|
||||
Reference in New Issue
Block a user