-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmithy-java.java-conventions.gradle.kts
145 lines (127 loc) · 3.96 KB
/
smithy-java.java-conventions.gradle.kts
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
import com.diffplug.spotless.FormatterFunc
import com.github.spotbugs.snom.Effort
import java.util.regex.Pattern
import org.gradle.api.Project
import org.gradle.kotlin.dsl.the
import java.io.Serializable
plugins {
`java-library`
id("com.adarshr.test-logger")
id("com.github.spotbugs")
id("com.diffplug.spotless")
id("com.autonomousapps.dependency-analysis")
id("smithy-java.utilities")
}
// Workaround per: https://github.com/gradle/gradle/issues/15383
val Project.libs get() = the<org.gradle.accessors.dm.LibrariesForLibs>()
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}
tasks.withType<Javadoc>() {
options.encoding = "UTF-8"
}
/*
* Common test configuration
* ===============================
*/
dependencies {
testImplementation(platform(libs.junit.bom))
testImplementation(libs.junit.jupiter.api)
testRuntimeOnly(libs.junit.jupiter.engine)
testImplementation(libs.junit.jupiter.params)
testImplementation(libs.hamcrest)
testImplementation(libs.assertj.core)
compileOnly("com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}")
testCompileOnly("com.github.spotbugs:spotbugs-annotations:${spotbugs.toolVersion.get()}")
}
tasks.withType<Test> {
useJUnitPlatform()
}
testlogger {
showExceptions = true
showStackTraces = true
showFullStackTraces = false
showCauses = true
showSummary = false
showPassed = false
showSkipped = false
showFailed = true
showOnlySlow = false
showStandardStreams = true
showPassedStandardStreams = false
showSkippedStandardStreams = false
showFailedStandardStreams = true
logLevel = LogLevel.WARN
}
/*
* Formatting
* ==================
* see: https://github.com/diffplug/spotless/blob/main/plugin-gradle/README.md#java
*/
spotless {
java {
// Enforce a common license header on all files
licenseHeaderFile("${project.rootDir}/config/spotless/license-header.txt")
.onlyIfContentMatches("^((?!SKIPLICENSECHECK)[\\s\\S])*\$")
leadingTabsToSpaces()
endWithNewline()
eclipse().configFile("${project.rootDir}/config/spotless/formatting.xml")
// Fixes for some strange formatting applied by eclipse:
// see: https://github.com/kamkie/demo-spring-jsf/blob/bcacb9dc90273a5f8d2569470c5bf67b171c7d62/build.gradle.kts#L159
// These have to be implemented with anonymous classes this way instead of lambdas because of:
// https://github.com/diffplug/spotless/issues/2387
custom("Lambda fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return input.replace("} )", "})").replace("} ,", "},")
}
})
custom("Long literal fix", object : Serializable, FormatterFunc {
override fun apply(input: String) : String {
return Pattern.compile("([0-9_]+) [Ll]").matcher(input).replaceAll("\$1L")
}
})
// Static first, then everything else alphabetically
removeUnusedImports()
importOrder("\\#", "")
// Ignore generated generated code for formatter check
targetExclude("**/build/**/*.*")
}
// Formatting for build.gradle.kts files
kotlinGradle {
ktlint()
leadingTabsToSpaces()
trimTrailingWhitespace()
endWithNewline()
}
}
/*
* Spotbugs
* ====================================================
*
* Run spotbugs against source files and configure suppressions.
*/
// Configure the spotbugs extension.
spotbugs {
effort = Effort.MAX
excludeFilter = file("${project.rootDir}/config/spotbugs/filter.xml")
}
// We don't need to lint tests.
tasks.named("spotbugsTest") {
enabled = false
}
tasks.spotlessCheck {
dependsOn(tasks.spotlessApply)
}
/*
* Repositories
* ================================
*/
repositories {
mavenLocal()
mavenCentral()
}