This project uses consistent code formatting across Eclipse and VSCode editors, enforced by Spotless.
- Indentation: 4 spaces (not tabs)
- Line length: 120 characters
- Braces: End of line (K&R style)
- File endings: Unix line endings (LF), files end with newline
- Whitespace: No trailing whitespace
Eclipse will automatically use the formatter configuration from .settings/eclipse-java-formatter.xml.
- The formatter is automatically imported when you open the project
- Format code:
Ctrl+Shift+F(Windows/Linux) orCmd+Shift+F(Mac) - Eclipse will format according to the GOSS profile
VSCode is configured to use the same Eclipse formatter for consistency.
- Format current file:
Shift+Alt+F(Windows/Linux) orShift+Option+F(Mac) - Format on save: Enabled by default (see
.vscode/settings.json) - Format selection: Select code, then
Ctrl+K Ctrl+F
The formatter configuration is in .vscode/settings.json:
"java.format.settings.url": ".settings/eclipse-java-formatter.xml"
"java.format.settings.profile": "GOSS"Check if code is properly formatted without making changes:
./gradlew spotlessCheckThis will:
- ✅ Pass if all code is properly formatted
- ❌ Fail and show violations if formatting is incorrect
Automatically fix formatting issues:
./gradlew spotlessApplyThis will:
- Format all Java files according to the Eclipse formatter
- Remove trailing whitespace
- Ensure files end with newline
- Fix line endings to Unix (LF)
# Check specific module
./gradlew :pnnl.goss.core:spotlessCheck
# Format specific module
./gradlew :pnnl.goss.core:spotlessApplyA GitHub Actions workflow automatically checks formatting on all pull requests:
Workflow: .github/workflows/format-check.yml
- Runs on every PR to
master,main, ordevelop - Uses
./gradlew spotlessCheckto validate formatting - ❌ Blocks PR if formatting is incorrect
- 💬 Comments on PR with fix instructions
Option 1: Run Spotless manually
./gradlew spotlessApply
git add .
git commit -m "Your message"Option 2: Use IDE formatter
- Eclipse:
Ctrl+Shift+F - VSCode:
Shift+Alt+For enable format-on-save
You can add a pre-commit hook to automatically check formatting:
# Create .git/hooks/pre-commit
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
./gradlew spotlessCheck
if [ $? -ne 0 ]; then
echo "❌ Code formatting check failed!"
echo "Run './gradlew spotlessApply' to fix formatting"
exit 1
fi
EOF
chmod +x .git/hooks/pre-commit- Reload VSCode Java Language Server:
Ctrl+Shift+P→Java: Clean Java Language Server Workspace
- Verify Java extension is installed:
- Extension ID:
redhat.java
- Extension ID:
- Check settings point to formatter:
- Open
.vscode/settings.json - Verify
java.format.settings.urlis set
- Open
- Verify formatter is imported:
- Window → Preferences → Java → Code Style → Formatter
- Should show "GOSS" profile
- Re-import formatter:
- Import →
.settings/eclipse-java-formatter.xml
- Import →
- Refresh project:
- Right-click project → Gradle → Refresh Gradle Project
After merging/pulling changes:
# Apply formatting to all files
./gradlew spotlessApply
# Commit the formatting changes
git add .
git commit -m "Apply code formatting"| File | Purpose |
|---|---|
.settings/eclipse-java-formatter.xml |
Eclipse formatter configuration (canonical) |
.settings/org.eclipse.jdt.core.prefs |
Eclipse Java compiler settings |
.vscode/settings.json |
VSCode Java formatter settings |
build.gradle |
Spotless plugin configuration |
.github/workflows/format-check.yml |
CI formatting check |
- Format before committing: Always run
./gradlew spotlessApplybefore pushing - Enable format-on-save: Both IDEs support automatic formatting
- Check CI before merging: Ensure GitHub Actions passes
- Don't mix formatting with logic: Commit formatting changes separately
- Use IDE shortcuts: Learn keyboard shortcuts for quick formatting
- Check QUICK-START.md for getting started
- See DEVELOPER-SETUP.md for build and project setup
- Open an issue for formatting configuration questions