Skip to content

Commit cd70d95

Browse files
committed
Improve build
1 parent aec6387 commit cd70d95

File tree

5 files changed

+39
-92
lines changed

5 files changed

+39
-92
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ plugins {
22
id "io.github.gradle-nexus.publish-plugin"
33
id "release-process"
44
id 'com.diffplug.spotless' version '6.25.0' apply false
5+
6+
id "com.dorongold.task-tree" version "4.0.0"
57
}
68

79
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

buildSrc/src/main/groovy/java-module.gradle

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ plugins {
33
id "java-library"
44

55
id "com.diffplug.spotless"
6-
id "checkstyle"
7-
86
id "jacoco"
97
}
108

@@ -52,9 +50,6 @@ tasks.withType( JavaCompile ).configureEach {javaCompile->
5250
options.warnings false
5351
}
5452

55-
tasks.named( "checkstyleMain" ) {
56-
dependsOn( tasks.named( "spotlessJavaApply" ) )
57-
}
5853

5954
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6055
// Javadoc
@@ -95,15 +90,46 @@ spotless {
9590

9691

9792
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98-
// Checkstyle
93+
// Enforced rules
9994
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10095

101-
checkstyle {
102-
sourceSets = [ project.sourceSets.main ]
103-
showViolations = false
96+
def enforceRulesTask = tasks.register( "enforceRules" ) {
97+
description "Enforces some formatting rules to src/main/java files"
98+
doLast {
99+
def illegalImport = ~/^import (sun|java.awt|org.slf4j)/
100+
def missingNewline = ~/^\s*}\s*(else|catch|finally)/
101+
def lowerEll = ~/\b\d+l\b/
102+
def errors = 0
103+
def tree = fileTree( "src/main/java/" )
104+
tree.include "**/*.java"
105+
tree.each { file ->
106+
def lineNum = 0
107+
def shortName = file.path.substring( rootDir.path.length() )
108+
file.eachLine { line ->
109+
lineNum++
110+
if ( line =~ illegalImport ) {
111+
errors++
112+
logger.error( "Illegal import in ${shortName}\n${lineNum}: ${line}" )
113+
}
114+
if ( line =~ missingNewline ) {
115+
errors++
116+
logger.error( "Missing newline in ${shortName}\n${lineNum}: ${line}" )
117+
}
118+
if ( line =~ lowerEll ) {
119+
errors++
120+
logger.error( "Lowercase long literal in ${shortName}\n${lineNum}: ${line}" )
121+
}
122+
}
123+
}
124+
if ( errors > 0 ) {
125+
throw new GradleException( "Code rules were violated ($errors problems)" )
126+
}
127+
}
104128
}
105129

106130

131+
132+
107133
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108134
// JaCoCo
109135
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -121,5 +147,7 @@ jacocoTestReport {
121147
}
122148

123149
tasks.named( "check" ) {
150+
dependsOn enforceRulesTask
151+
dependsOn tasks.named( "spotlessCheck" )
124152
dependsOn jacocoReportTask
125153
}

config/checkstyle/checkstyle.xml

Lines changed: 0 additions & 69 deletions
This file was deleted.

config/checkstyle/headers/header-java.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

config/checkstyle/headers/header-xml.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)