Skip to content

Commit

Permalink
Enable Spotless for automatic formatting (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 9, 2023
1 parent f215f9d commit a76d8ec
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ Starting from Plugin POM `4.40`, support of Java 17 was added.
You can configure your plugin to treat every commit as a release candidate.
See [Incrementals](https://github.com/jenkinsci/incrementals-tools) for details.

## Formatting

To opt in to code formatting of your Java sources and Maven POM with Spotless,
create a `.mvn_exec_spotless` file at the root of your repository and remove
any existing Spotless configuration from your POM.

To format existing code, run:

```bash
mvn spotless:apply
```

After formatting an existing repository, squash merge the PR and create a
[`.git-blame-ignore-revs`](https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view)
file to hide the formatting commit from blame tools.

## Running Benchmarks

To run JMH benchmarks from JUnit tests, you must run you must activate the `benchmark`
Expand Down
50 changes: 50 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
<mockito.version>5.2.0</mockito.version>
<spotbugs-maven-plugin.version>4.7.3.4</spotbugs-maven-plugin.version>
<spotless-maven-plugin.version>2.36.0</spotless-maven-plugin.version>
<stapler-plugin.version>1.23</stapler-plugin.version>

<!-- Filled in by "maven-hpi-plugin" with the path to "org-netbeans-insane-hook.jar" extracted from "jenkins-test-harness" -->
Expand Down Expand Up @@ -301,6 +302,11 @@
<artifactId>maven-license-plugin</artifactId>
<version>${maven-license-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${spotless-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down Expand Up @@ -875,6 +881,7 @@
<properties>
<skipTests>${release.skipTests}</skipTests>
<spotbugs.skip>${release.skipTests}</spotbugs.skip>
<spotless.check.skip>${release.skipTests}</spotless.check.skip>
<invoker.skip>${release.skipTests}</invoker.skip>
</properties>
<build>
Expand Down Expand Up @@ -1413,6 +1420,49 @@
</plugins>
</build>
</profile>
<profile>
<id>spotless-execution</id>
<activation>
<file>
<exists>.mvn_exec_spotless</exists>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<endWithNewline />
<importOrder />
<indent>
<spaces>true</spaces>
</indent>
<palantirJavaFormat />
<removeUnusedImports />
<trimTrailingWhitespace />
</java>
<pom>
<sortPom>
<expandEmptyElements>false</expandEmptyElements>
<sortDependencies>scope,groupId,artifactId</sortDependencies>
<sortDependencyExclusions>groupId,artifactId</sortDependencyExclusions>
<spaceBeforeCloseEmptyElement>true</spaceBeforeCloseEmptyElement>
</sortPom>
</pom>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<!-- a profile that disables as much testing as possible whilst still producing the artifacts -->
Expand Down

0 comments on commit a76d8ec

Please sign in to comment.