@@ -9,7 +9,7 @@ A set of plugins that can be applied to any Java project to provide a consistent
9
9
The set currently consists of:
10
10
11
11
* A source formatter that applies wrapping and whitespace conventions
12
- * A checkstyle plugin that enforces consistency across a codebase
12
+ * A Checkstyle plugin that enforces consistency across a codebase
13
13
14
14
Since the aim of this project is to provide consistency, each plugin is not generally configurable.
15
15
You need to change your code to match the required conventions.
@@ -82,7 +82,7 @@ If you want to skip both, you can use `-Dspring-javaformat.skip=true`.
82
82
83
83
84
84
==== Checkstyle
85
- To enforce checkstyle conventions, add the checkstyle plugin and include a dependency on `spring-javaformat-checkstyle`:
85
+ To enforce Checkstyle conventions, add the Checkstyle plugin and include a dependency on `spring-javaformat-checkstyle`:
86
86
87
87
[source,xml,indent=0,subs="normal"]
88
88
----
@@ -126,46 +126,49 @@ To enforce checkstyle conventions, add the checkstyle plugin and include a depen
126
126
127
127
128
128
=== Gradle
129
+ A plugin is provided.
130
+ To use it, first update `settings.gradle` to add Maven Central as a plugin repository:
129
131
132
+ [source,groovy,indent=0,subs="normal"]
133
+ pluginManagement {
134
+ repositories {
135
+ gradlePluginPortal()
136
+ mavenCentral()
137
+ }
138
+ }
130
139
131
-
132
- ==== Source Formatting
133
- For source formatting, add the `spring-javaformat-gradle-plugin` to your `build` plugins as follows:
140
+ The plugin can then be added in the usual way in `build.gradle`:
134
141
135
142
[source,groovy,indent=0,subs="normal"]
136
143
----
137
- buildscript {
138
- repositories {
139
- mavenCentral()
140
- }
141
- dependencies {
142
- classpath("io.spring.javaformat:spring-javaformat-gradle-plugin:{release-version}")
143
- }
144
- }
145
-
146
- apply plugin: 'io.spring.javaformat'
144
+ plugins {
145
+ id "io.spring.javaformat" version "{release-version}""
146
+ }
147
147
----
148
148
149
+ ==== Source Formatting
149
150
The plugin adds `format` and `checkFormat` tasks to your project.
150
- The `checkFormat` task is automatically applied when running the standard Gradle `check` task.
151
+ The `checkFormat` task is automatically executed when running the standard Gradle `check` task.
151
152
152
- In case you want to exclude a package from being checked, for example if you generate sources, you can do this by adding the following configuration :
153
+ In case you want to exclude a package from being checked, for example if you generate sources, add configuration similar to the following:
153
154
154
155
[source,groovy,indent=0,subs="normal"]
155
156
----
156
157
tasks.withType(io.spring.javaformat.gradle.tasks.CheckFormat) {
157
- exclude "package/to/exclude"
158
+ exclude "package/to/exclude"
158
159
}
159
160
----
160
161
161
162
162
163
163
164
==== Checkstyle
164
- To enforce checkstyle conventions, add the checkstyle plugin and include a dependency on `spring-javaformat-checkstyle`:
165
+ To enforce Checkstyle conventions, add the ` checkstyle` plugin and include a dependency on `spring-javaformat-checkstyle`:
165
166
166
167
[source,groovy,indent=0,subs="normal"]
167
168
----
168
- apply plugin: 'checkstyle'
169
+ plugins {
170
+ id "checkstyle"
171
+ }
169
172
170
173
checkstyle {
171
174
toolVersion = "{checkstyle-version}"
@@ -176,7 +179,7 @@ dependencies {
176
179
}
177
180
----
178
181
179
- Your `checkstyle.xml` file should look then like this:
182
+ To use the Spring checks, your `checkstyle.xml` file should look like this:
180
183
181
184
[source,xml,indent=0]
182
185
----
@@ -368,7 +371,7 @@ If you find you need whitespace inside your method, consider whether extracting
368
371
Try to add javadoc for each public method and constant.
369
372
Private methods shouldn't generally need javadoc, unless it provides a natural place to document unusual behavior.
370
373
371
- The checkstyle rules will enforce that all public classes have javadoc.
374
+ The Checkstyle rules will enforce that all public classes have javadoc.
372
375
They will also ensure that `@author` tags are well formed.
373
376
374
377
0 commit comments