-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
158 lines (130 loc) · 3.94 KB
/
build.gradle.kts
File metadata and controls
158 lines (130 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
// Apply the Java plugin for Java development
java
// Apply Kotlin plugin for mixed Java/Kotlin projects (optional)
kotlin("jvm") version "1.9.22"
// Code quality plugins
id("com.github.spotbugs") version "6.0.8"
id("checkstyle")
id("pmd")
// Test reporting
id("jacoco")
}
repositories {
// Use Maven Central for resolving dependencies
mavenCentral()
}
// Dependency resolution strategy to handle conflicts
configurations.all {
resolutionStrategy {
// Force specific versions to resolve conflicts
force("com.google.guava:guava:33.0.0-jre")
// Exclude problematic dependencies
exclude(group = "com.google.collections", module = "google-collections")
}
}
dependencies {
// Use JUnit Jupiter for testing
testImplementation("org.junit.jupiter:junit-jupiter:5.10.1")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
// Mockito for mocking in tests
testImplementation("org.mockito:mockito-core:5.8.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.8.0")
// AssertJ for fluent assertions
testImplementation("org.assertj:assertj-core:3.25.1")
// Kotlin standard library (if using Kotlin)
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
// Common utilities
implementation("org.apache.commons:commons-lang3:3.14.0")
implementation("com.google.guava:guava:33.0.0-jre")
// Logging
implementation("ch.qos.logback:logback-classic:1.4.14")
implementation("org.slf4j:slf4j-api:2.0.10")
}
// Apply a specific Java toolchain to ease working on different environments
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}
kotlin {
jvmToolchain(21)
}
application {
// Define the main class for the application
mainClass.set("com.example.gradle.App")
}
tasks.named<Test>("test") {
// Use JUnit Platform for unit tests
useJUnitPlatform()
// Enable test result logging
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showStandardStreams = false
}
// Generate test report
finalizedBy(tasks.jacocoTestReport)
}
tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
xml.required.set(true)
html.required.set(true)
csv.required.set(false)
}
}
tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.80".toBigDecimal()
}
}
}
}
// Checkstyle configuration
checkstyle {
toolVersion = "10.18.2"
configFile = file("config/checkstyle/checkstyle.xml")
isIgnoreFailures = false
}
// PMD configuration
pmd {
toolVersion = "7.7.0"
isConsoleOutput = true
ruleSetFiles = files("config/pmd/ruleset.xml")
ruleSets = listOf() // Clear default rule sets
}
// SpotBugs configuration
spotbugs {
toolVersion = "4.8.6"
effort = com.github.spotbugs.snom.Effort.MAX
reportLevel = com.github.spotbugs.snom.Confidence.LOW
excludeFilter = file("config/spotbugs/exclude.xml")
}
tasks.spotbugsMain {
reports.create("html") {
required.set(true)
outputLocation.set(file("build/reports/spotbugs/main.html"))
}
}
tasks.spotbugsTest {
reports.create("html") {
required.set(true)
outputLocation.set(file("build/reports/spotbugs/test.html"))
}
}
// Custom tasks
tasks.register("codeQuality") {
group = "verification"
description = "Runs all code quality checks"
dependsOn("checkstyleMain", "pmdMain", "spotbugsMain", "test", "jacocoTestCoverageVerification")
}
tasks.register("cleanBuild") {
group = "build"
description = "Clean and build the project"
dependsOn("clean", "build")
}