-
Notifications
You must be signed in to change notification settings - Fork 4
/
formatter.gradle
78 lines (64 loc) · 2.9 KB
/
formatter.gradle
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
/*
* Minimal gradle build file for calling spotless
* java formatter
* https://github.com/diffplug/spotless - formatter for java and others
* (tasks: spotlessCheck, spotlessApply resp. spotlessApplyJava)
*
* Run via maven:
mvn org.fortasoft:gradle-maven-plugin:invoke
*/
buildscript {
repositories {
//mavenLocal()
mavenCentral()
//maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.4.0"
}
}
apply plugin: "com.diffplug.gradle.spotless"
apply plugin: 'java'
compileJava {
sourceCompatibility = '1.7'
}
/*
* Code formatter - https://github.com/diffplug/spotless
*/
project.plugins.withId('com.diffplug.gradle.spotless') {
spotless {
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore'
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
}
// for formatter config see src/config/eclipse/formatter/java.xml
java {
importOrderFile 'src/config/spotless/spotless.importorder'
// based on XML file dumped out by the Eclipse formatter
eclipse().configFile('src/config/eclipse/formatter/java.xml')
// eclipseFormatFile('src/config/eclipse/formatter/java.xml')
// Note: this may be slow
removeUnusedImports()
indentWithSpaces()
trimTrailingWhitespace()
endWithNewline()
// eclipse formatter indents empty lines even if option is set to false.
replaceRegex 'Empty line indent fix', '^ +$', ''
// use standard modifier order (JLS 4.8.7 Modifiers)
// public protected private abstract static final transient volatile synchronized native strictfp
replaceRegex 'Modifier order 1', '^(\\s*)((?:static)|(?:final)|(?:abstract))\\s+((public)|(protected)|(private))\\s',
'$1$3 $2 '
replaceRegex 'Modifier order 2', '^(\\s*)final\\s+static\\s+((public)|(protected)|(private))\\s', '$1$2 static final '
replaceRegex 'Modifier order 3', '^(\\s*)static\\s+final\\s+((public)|(protected)|(private))\\s', '$1$2 static final '
replaceRegex 'Modifier order 4', '^(\\s*((public)|(protected)|(private))?\\s*)\\sfinal\\s+static', '$1 static final'
// remove empty lines before end of block (closing "}")
replaceRegex 'Remove empty lines before end of block', '\\n[\\n]+(\\s*})(?=\\n)', '\n$1'
replaceRegex 'Remove trailing empty comment lines.', '\n\\s*\\*(\n\\s*\\*/\n)', '$1'
replaceRegex 'Remove empty javadoc param tags.', '\n\\s*\\* @param \\w+\n', '\n'
replaceRegex 'Remove empty javadoc return tags.', '\n\\s*\\* @return\n', '\n'
replaceRegex 'Replace exception tag with throws tag.', '(\n\\s*\\* )@exception ', '$1@throws '
}
}
}