1
1
# sbt-checkstyle-plugin
2
2
3
+ [ ![ Build Status] ( https://img.shields.io/github/workflow/status/stringbean/sbt-checkstyle-plugin/ci )] ( https://github.com/stringbean/sbt-checkstyle-plugin/actions/workflows/ci.yml )
4
+ [ ![ Known Vulnerabilities] ( https://snyk.io/test/github/stringbean/sbt-checkstyle-plugin/badge.svg?targetFile=build.sbt )] ( https://snyk.io/test/github/stringbean/sbt-checkstyle-plugin?targetFile=build.sbt )
5
+ ![ Maven Central] ( https://maven-badges.herokuapp.com/maven-central/software.purpledragon/sbt-checkstyle-plugin/badge.svg?style=flat )
6
+ ![ Checkstyle 3.9] ( https://img.shields.io/badge/Default_Checkstyle-3.9-yellowgreen )
7
+
3
8
This project provides an sbt plugin for running Checkstyle over Java source files. For more information about
4
9
Checkstyle, see [ checkstyle.sourceforge.io] ( http://checkstyle.sourceforge.io ) .
5
10
6
- This plugin uses version 6.15 of Checkstyle by default.
7
-
8
11
This project was forked from [ etsy/sbt-checkstyle-plugin] ( https://github.com/etsy/sbt-checkstyle-plugin ) in 2022
9
12
after it became unmaintained. Some initial code was based on an
10
13
[ earlier plugin] ( https://github.com/corux/sbt-code-quality ) (dead link).
@@ -17,20 +20,20 @@ Add the following lines to `project/plugins.sbt`:
17
20
addSbtPlugin(" software.purpledragon" % " sbt-checkstyle-plugin" % " <version>" )
18
21
```
19
22
20
- sbt-checkstyle-plugin is an AutoPlugin, so there is no need to modify the ` build.sbt ` file to enable it .
23
+ Checkstyle will be enabled by default for projects .
21
24
22
25
## Usage
23
26
24
27
You can run Checkstyle over your Java source files with the ` checkstyle ` task. You can run Checkstyle over your Java
25
- tests with the ` test: checkstyle` task.
28
+ tests with the ` Test / checkstyle` task.
26
29
27
- The Checkstyle configuration file is ` ./ checkstyle-config.xml` by default. This can be changed by setting the value of
28
- ` checkstyleConfigLocation ` . By default ` test: checkstyle` uses the same configuration file, but this can be changed by
29
- setting the value of ` checkstyleConfigLocation in Test ` .
30
+ The Checkstyle configuration file is ` checkstyle-config.xml ` by default. This can be changed by setting the value of
31
+ ` checkstyleConfigLocation ` . By default ` Test / checkstyle` uses the same configuration file, but this can be changed
32
+ by setting the value of ` Test / checkstyleConfigLocation ` .
30
33
31
34
The Checkstyle report is output to ` target/checkstyle-report.xml ` by default. This can be changed by setting the value
32
- of ` checkstyleOutputFile ` . ` test: checkstyle` outputs to ` target/checkstyle-test-report.xml ` , but this can be changed by
33
- setting the value of ` checkstyleOutputFile in Test ` .
35
+ of ` checkstyleOutputFile ` . ` Test / checkstyle` outputs to ` target/checkstyle-test-report.xml ` , but this can be changed
36
+ by setting the value of ` Test / checkstyleOutputFile ` .
34
37
35
38
To change the checkstyle configuration file set ` checkstyleConfigLocation ` in ` build.sbt ` :
36
39
``` scala
@@ -50,36 +53,36 @@ checkstyleConfigLocation := CheckstyleConfigLocation.Classpath("com/etsy/checkst
50
53
51
54
To run Checkstyle automatically after compilation:
52
55
``` scala
53
- (checkstyle in Compile ) := (checkstyle in Compile ).triggeredBy(compile in Compile ).value
56
+ (Compile / checkstyle ) := (Compile / checkstyle ).triggeredBy(Compile / compile ).value
54
57
```
55
58
56
59
To run Checkstyle automatically after test compilation:
57
60
``` scala
58
- (checkstyle in Test ) := (checkstyle in Test ).triggeredBy(compile in Test ).value
61
+ (Test / checkstyle ) := (Test / checkstyle ).triggeredBy(Test / compile ).value
59
62
```
60
63
61
64
### XSLT transformations
62
65
63
66
The ` checkstyleXsltTransformations ` setting allows applying XSLT transformations to the XML report generated by
64
67
Checkstyle. For instance, this could be used to generate a more readable HTML report. This setting takes values of
65
- ` Option[ Set[XSLTSettings] ]` , so multiple transformations can be applied.
68
+ ` Set[XSLTSettings] ` , so multiple transformations can be applied.
66
69
67
70
You can set ` checkstyleXsltTransformations ` like so in ` build.sbt ` :
68
71
``` scala
69
- checkstyleXsltTransformations := {
70
- Some (Set (CheckstyleXSLTSettings (baseDirectory(_ / " checkstyle-noframes.xml" ).value, target(_ / " checkstyle-report.html" ).value)))
71
- }
72
+ checkstyleXsltTransformations +=
73
+ CheckstyleXSLTSettings (baseDirectory.value / " checkstyle-noframes.xml" , target.value / " checkstyle-report.html" )
72
74
```
73
75
74
76
### Failing the build
75
77
76
78
You can control what severity of issues should break the build by setting the ` checkstyleSeverityLevel ` in your
77
79
` build.sbt ` as follows:
80
+
78
81
``` scala
79
- checkstyleSeverityLevel := Some ( CheckstyleSeverityLevel .Error )
82
+ checkstyleSeverityLevel := CheckstyleSeverityLevel .Error
80
83
```
81
84
82
- Possible values are defined by the ` CheckstyleSeverityLevel ` enumeration. The default is ` None ` .
85
+ Possible values are defined by the ` CheckstyleSeverityLevel ` enumeration. The default is ` Ignore ` .
83
86
84
87
### Integration tests
85
88
@@ -89,12 +92,12 @@ lazy val root = (project in file(".")).configs(IntegrationTest)
89
92
90
93
Defaults .itSettings
91
94
92
- checkstyleConfigLocation := CheckstyleConfigLocation .File (" my-checkstyle-config.xml" ),
93
- checkstyle in IntegrationTest := checkstyleTask(IntegrationTest ).value,
94
- checkstyleOutputFile in IntegrationTest := target.value / " checkstyle-integration-test-report.xml"
95
+ checkstyleConfigLocation := CheckstyleConfigLocation .File (" my-checkstyle-config.xml" )
96
+ IntegrationTest / checkstyle := checkstyleTask(IntegrationTest ).value
97
+ IntegrationTest / checkstyleOutputFile := target.value / " checkstyle-integration-test-report.xml"
95
98
```
96
99
97
- You can then run the tasks ` it: checkstyle` and ` it: checkstyle-check` .
100
+ You can then run the tasks ` IntegrationTest / checkstyle` and ` IntegrationTest / checkstyle-check` .
98
101
99
102
### Upgrading Checkstyle version
100
103
@@ -104,27 +107,31 @@ Provided the new Checkstyle version is compatible, you can override the version
104
107
` project/plugins.sbt ` :
105
108
106
109
``` scala
107
- dependencyOverrides += " com.puppycrawl.tools" % " checkstyle" % " 6.15 "
110
+ dependencyOverrides += " com.puppycrawl.tools" % " checkstyle" % " 10.3 "
108
111
```
109
112
110
113
## Settings
111
114
112
115
### ` checkstyleOutputFile `
113
- * * Description:* The location of the generated checkstyle report.
114
- * * Accepts:* any legal file path
115
- * * Default:* ` Some(target.value / "checkstyle-report.xml") `
116
+
117
+ - ** Description:** The location of the generated checkstyle report.
118
+ - ** Accepts:** ` File `
119
+ - ** Default:** ` target.value / "checkstyle-report.xml" `
116
120
117
121
### ` checkstyleConfigLocation `
118
- * * Description:* The location of the checkstyle configuration file.
119
- * * Accepts:* ` CheckstyleConfigLocation.{File, URL, Classpath} `
120
- * * Default:* ` CheckstyleConfigLocation.File("checkstyle-config.xml") `
122
+
123
+ - ** Description:** The location of the checkstyle configuration file.
124
+ - ** Accepts:** ` CheckstyleConfigLocation ` (` .File ` , ` .URL ` , ` .Classpath ` )
125
+ - ** Default:** ` CheckstyleConfigLocation.File("checkstyle-config.xml") `
121
126
122
127
### ` checkstyleXsltTransformations `
123
- * * Description:* A set of XSLT transformations to be applied to the checkstyle output (optional).
124
- * * Accepts:* ` Some(Set[CheckstyleXSLTSettings]) `
125
- * * Default:* ` None `
128
+
129
+ - ** Description:** A set of XSLT transformations to be applied to the checkstyle output.
130
+ - ** Accepts:** ` Set[CheckstyleXSLTSettings] `
131
+ - ** Default:** ` Set.empty `
126
132
127
133
### ` checkstyleSeverityLevel `
128
- * * Description:* Decide how much effort to put into analysis.
129
- * * Accepts:* ` Some(CheckstyleSeverityLevel.{Ignore, Info, Warning, Error}) `
130
- * * Default:* ` None `
134
+
135
+ - ** Description:** Decide how much effort to put into analysis.
136
+ - ** Accepts:** ` CheckstyleSeverityLevel ` (` Ignore ` , ` Info ` , ` Warning ` , ` Error ` )
137
+ - ** Default:** ` CheckstyleSeverityLevel.Ignore `
0 commit comments