-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
89 lines (78 loc) · 2.7 KB
/
Copy pathbuild.gradle
File metadata and controls
89 lines (78 loc) · 2.7 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
plugins {
id 'com.diffplug.spotless' version '6.25.0' apply false
}
subprojects {
apply plugin: 'java'
apply plugin: 'com.diffplug.spotless'
group = 'com.auction'
version = '1.0-SNAPSHOT'
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
tasks.withType(Test).configureEach {
useJUnitPlatform()
}
spotless {
java {
target 'src/**/*.java'
googleJavaFormat('1.35.0')
removeUnusedImports()
formatAnnotations()
}
}
tasks.register('checkGoogleJavaStyleHardRules') {
def javaSources = fileTree(projectDir) {
include 'src/**/*.java'
exclude '**/build/**'
}
inputs.files(javaSources)
doLast {
def violations = []
javaSources.files.each { source ->
if (!source.name.endsWith('.java')) {
return
}
def hasPackage = false
source.eachLine { line, number ->
if (number <= 5 && line ==~ /\s*package\s+[^;]+;/) {
hasPackage = true
}
if (line.contains('\t')) {
violations << "${source}:${number}: tab characters are not allowed"
}
if (line ==~ /\s*import\s+(static\s+)?[^;]*\.\*;/) {
violations << "${source}:${number}: wildcard imports are not allowed"
}
if (!(line ==~ /\s*(package|import)\s+.*/) && line.length() > 100) {
violations << "${source}:${number}: line exceeds 100 columns"
}
if (line =~ /[âÃ�]/) {
violations << "${source}:${number}: possible encoding-damaged text"
}
}
if (!hasPackage) {
violations << "${source}:1: missing package declaration"
}
}
if (!violations.isEmpty()) {
throw new GradleException(
"Google Java Style hard-rule violations:\n" + violations.join('\n'))
}
}
}
tasks.named('check') {
dependsOn tasks.named('spotlessCheck')
dependsOn tasks.named('checkGoogleJavaStyleHardRules')
}
}