A command-line tool for formatting Java code using Eclipse's code formatter in headless mode. Provides a simple, user-friendly interface for consistent code formatting across projects.
- 🚀 Simple CLI interface - Easy to use with intuitive commands
- ⚡ Fast formatting - Leverages Eclipse's proven formatter engine
- 🔧 Customisable - Use your own Eclipse formatter configuration
- 📁 Batch processing - Format single files or entire directories
- 🔍 Dry run mode - Preview changes before applying
- 🔄 Recursive formatting - Process nested directories
- 🧪 Tested - Comprehensive unit and integration tests
- 🏗️ IDE friendly - Works with Eclipse and IntelliJ IDEA
# Clone and setup in one go
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./setup.sh
# Now use it!
./eclipse-format --helpgit clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./install.sh
# Choose from:
# 1. System-wide installation (requires sudo)
# 2. Local user installation (~/.local/bin)
# 3. Standalone script
# 4. Just buildgit clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./gradlew shadowJar
./eclipse-format.sh --help # Auto-finds the JAR!git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
./gradlew shadowJar
java -jar build/libs/eclipse-format.jar --helpgit clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
gradlew.bat shadowJar
eclipse-format.bat --help# Format a single Java file
eclipse-format MyClass.java
# Format all Java files in a directory
eclipse-format src/
# Format recursively
eclipse-format -r src/
# Dry run (show what would change)
eclipse-format -d src/
# Verbose output
eclipse-format -v MyClass.java
# Use custom configuration file
eclipse-format -c my-formatter.xml MyClass.javaUsage: eclipse-format [-cdrv] [-c=<configFile>] <target>
<target> File or directory to format
-c, --config=<configFile>
Path to Eclipse formatter configuration file
-d, --dry-run Show what would be formatted without making changes
-r, --recursive Format files recursively
-v, --verbose Verbose output
--help Show this help message and exit
--version Print version information and exit
The tool uses Eclipse's XML formatter configuration files. You can:
- Export from Eclipse IDE: Window → Preferences → Java → Code Style → Formatter → Export...
- Use the default included in this project (
eclipse-format.xml) - Create your own XML configuration
Example configuration file structure:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<profiles version="20">
<profile kind="CodeFormatterProfile" name="My Profile" version="20">
<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
<!-- More settings... -->
</profile>
</profiles>- Java 15 or higher
- Gradle 8.5 or higher
# Clone and setup
git clone https://github.com/algodesigner/eclipse-format.git
cd eclipse-format
# Setup for Eclipse
./gradlew setupEclipse
# Setup for IntelliJ IDEA
./gradlew setupIntelliJ
# Clean IDE files
./gradlew cleanIDE# Build the project
./gradlew build
# Run tests
./gradlew test
# Run integration tests
./gradlew integrationTest
# Create executable JAR
./gradlew shadowJar
# Run the application
./gradlew run --args="-v MyClass.java"eclipse-format/
├── src/
│ ├── main/java/com/algodesigner/eclipseformat/cli/
│ │ ├── EclipseFormatCli.java # Main CLI entry point
│ │ └── FormatterService.java # Core formatting logic
│ └── test/java/com/algodesigner/eclipseformat/cli/
│ ├── EclipseFormatCliTest.java # Unit tests
│ └── IntegrationTest.java # Integration tests
├── eclipse-format.xml # Default formatter config
├── build.gradle # Gradle build configuration
├── gradlew # Gradle wrapper
└── README.md # This file
# Format all Java files in your project
eclipse-format -r src/main/java/
# With custom configuration
eclipse-format -c company-style.xml -r src/# See what files would be formatted
eclipse-format -d -r src/
# Output:
# [DRY RUN] Would format: src/main/java/com/example/Main.java
# [DRY RUN] Would format: src/main/java/com/example/Util.java# Check if code is properly formatted (exit code 0 if formatted, 1 if not)
eclipse-format -d -r src/ && echo "Code is properly formatted"The project includes comprehensive test coverage:
# Run all tests
./gradlew test
# Run specific test class
./gradlew test --tests "EclipseFormatterCliTest"
# Run integration tests
./gradlew test --tests "IntegrationTest"
# Generate test coverage report
./gradlew jacocoTestReport- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Please ensure your code follows the project's formatting rules:
# Format your code before submitting
./gradlew run --args="src/main/java/"This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
Easy removal with the uninstall script:
# Interactive uninstall (recommended)
./uninstall.sh
# Remove everything
./uninstall.sh --all
# Clean up PATH entries
./uninstall.sh --clean-pathSee USAGE.md for complete uninstall options.
- 📖 Documentation: README.md and USAGE.md
- 🐛 Issues: Report installation or usage issues
- 🔧 Uninstall: Use
./uninstall.shfor clean removal
- Built with Picocli for CLI parsing
- Uses Eclipse's Java Development Tools for formatting
- Inspired by the need for consistent code formatting in CI/CD pipelines
Made with ❤️ by Vlad Shurupov for clean code everywhere