Skip to content

Commit

Permalink
Add 'may-spotless-apply' profile (#1017)
Browse files Browse the repository at this point in the history
I often find myself forgetting to apply spotless before committing.

On some repositories, I have set up a pre-commit git hook running `mvn
spotless:check`. However, this has to be set up on each repository that
has spotless check enabled, and disabled on those which don't.

I think this goes one step further, by defining a conventional maven
profile `may-spotless-apply` that will run `spotless:apply` *only* if
spotless is enabled for the given repository.

This allows any user to incorporate `-Pmay-spotless-apply` as part of
their usual build command (or defined in their maven settings active profiles section),
and have `spotless:apply` automatically called if the project has it enabled.
  • Loading branch information
Vlatombe authored Sep 24, 2024
1 parent ba03413 commit bd5687b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ 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.

### Format as you build

You can set up `mvn spotless:apply` to run automatically (in `validate` phase) for projects which enabled spotless by adding the following to your `settings.xml`:

```xml
<settings>
[...]
<activeProfiles>
[...]
<activeProfile>may-spotless-apply</activeProfile>
</activeProfiles>
</settings>
```

## Running Benchmarks

To run JMH benchmarks from JUnit tests, you must run you must activate the `benchmark`
Expand Down
23 changes: 23 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,5 +1461,28 @@
<maven.compiler.release>21</maven.compiler.release>
</properties>
</profile>
<profile>
<id>may-spotless-apply</id>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<executions>
<execution>
<id>spotless-apply</id>
<goals>
<goal>apply</goal>
</goals>
<phase>validate</phase>
<configuration>
<skip>${spotless.check.skip}</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

0 comments on commit bd5687b

Please sign in to comment.