https://github.com/rbiedrawa/java-gradle-codestyle-setup
Reference project template with code style settings for Java / Gradle projects
https://github.com/rbiedrawa/java-gradle-codestyle-setup
git-hooks google-java-format gradle intelij palantir spotless spotless-gradle spring-boot
Last synced: about 1 year ago
JSON representation
Reference project template with code style settings for Java / Gradle projects
- Host: GitHub
- URL: https://github.com/rbiedrawa/java-gradle-codestyle-setup
- Owner: rbiedrawa
- License: mit
- Created: 2022-02-02T14:28:45.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-24T11:24:13.000Z (about 4 years ago)
- Last Synced: 2025-01-26T18:17:20.993Z (about 1 year ago)
- Topics: git-hooks, google-java-format, gradle, intelij, palantir, spotless, spotless-gradle, spring-boot
- Language: Java
- Homepage:
- Size: 88.9 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Reference project template with code style settings for Java / Gradle projects
This repository contains code style settings that can be used to ensure formatting consistency inside Java / Gradle projects.
Project is configured to use [Spotless](https://github.com/diffplug/spotless) with [Palantir java format](https://github.com/palantir/palantir-java-format) which is based on
the [Google java format](https://github.com/google/google-java-format).
# Getting Started
## Usage
### Gradle
Use below command to apply `Spotless` code formatting steps
```shell
./gradlew spotlessApply
```
### Git (pre-commit Hook)
Run `spotlessApply` automatically on every commit.
#### Installation:
1. Install pre-commit
```shell
brew install pre-commit
```
2. Open new terminal and go to **project** directory
3. Install pre-commit hook using [.pre-commit-config.yaml](./.pre-commit-config.yaml)
```shell
pre-commit install
```
#### Uninstall:
```shell
rm ./.git/hooks/pre-commit
```
### Intelij plugin
#### Installation:
A [palantir-java-format IntelliJ plugin](https://plugins.jetbrains.com/plugin/13180-palantir-java-format/)
is available from the plugin repository. To install it, go to your IDE's settings and select the `Plugins` category.
Click the `Marketplace` tab, search for the `palantir-java-format` plugin, and click the `Install` button.
#### Usage:
The plugin will be disabled by default on new projects but if using the `com.palantir.java-format` gradle plugin, it
will be recommended in IntelliJ and automatically configured.
To manually enable it in the current project, go to `File→Settings...→palantir-java-format Settings` (
or `IntelliJ IDEA→Preferences...→Other Settings→palantir-java-format Settings` on macOS) and check
the `Enable palantir-java-format` checkbox.
When enabled, it will replace the normal `Reformat Code` action, which can be triggered from the `Code` menu or with the
Ctrl-Alt-L (by default) keyboard shortcut.
#### Caution:
Custom [codeStyles](./.idea/codeStyles) settings are stored inside this repository and they will be used automatically, in order to ensure correct import orders and other formatting rules inside Intelij IDE.
## References
* [Spotless gradle plugin](https://github.com/diffplug/spotless/tree/main/plugin-gradle)
* [Pre-commit](https://pre-commit.com/#usage)
* [Palantir Java Format plugin](https://github.com/palantir/palantir-java-format)
* [Intelij Palantir Java Format plugin](https://plugins.jetbrains.com/plugin/13180-palantir-java-format/)
## License
Distributed under the MIT License. See `LICENSE` for more information.