maven
maven copied to clipboard
Add CI optimizations for Maven 4.0
Summary
This PR implements automatic CI optimizations for Maven 4.0 to improve the CI/CD experience by automatically enabling appropriate settings when CI environments are detected.
Changes
High Priority CI Optimizations
-
Auto-enable batch mode (
--batch-mode/-B) when CI is detected to prevent hanging on interactive prompts -
Auto-enable show-version (
--show-version) for better CI build identification in logs -
Auto-enable show-errors (
--show-errors/-e) for improved CI debugging and error visibility
Key Features
- Respects user choices: Explicit command-line options always override CI defaults
- Comprehensive CI detection: Works with existing CI detection infrastructure (GitHub Actions, Travis CI, Jenkins, CircleCI, TeamCity, etc.)
- Informative logging: Users are informed when CI optimizations are applied
- Backward compatible: No breaking changes to existing functionality
- Well tested: Comprehensive unit and integration test coverage
Implementation Details
Core Components
-
CIAwareMavenOptions: New wrapper class that provides CI-specific defaults while preserving user explicit choices -
Modified
MavenInvoker: Integrates CI-aware options and adds informative logging - Comprehensive test suite: 12 tests covering all scenarios including user overrides
How It Works
// Apply CI-specific defaults if CI is detected and not overridden by user
if (invokerRequest.ciInfo().isPresent() && options != null) {
options = new CIAwareMavenOptions(options, invokerRequest.ciInfo().get());
}
Example CI Logging
Applying CI optimizations for detected CI system: 'GitHub Actions'
- Enabled batch mode (non-interactive)
- Enabled show-version for build identification
- Enabled show-errors for better debugging
To disable CI optimizations, use --force-interactive or set explicit options.
Benefits for CI Environments
- Prevents hanging builds: Batch mode eliminates interactive prompts that can hang CI builds
- Better build identification: Show-version provides clear version info in CI logs
- Improved debugging: Show-errors provides better error visibility for failed CI builds
- Zero configuration: Works automatically without requiring users to remember CI-specific flags
User Override Options
Users can still override these defaults when needed:
-
--force-interactive- Forces interactive mode even in CI -
--quiet- Overrides show-version and show-errors - Explicit flags like
--no-show-versionor--no-show-errors
Testing
- ✅ All existing tests pass
- ✅ 8 new unit tests in
CIAwareMavenOptionsTest - ✅ 4 new integration tests in
CIOptimizationsIntegrationTest - ✅ Code formatting and style checks pass
Addresses
- Fixes #11088 - Auto-enable batch mode in CI environments
- Provides additional valuable CI optimizations beyond just batch mode
Compatibility
- ✅ Fully backward compatible
- ✅ No breaking changes
- ✅ Respects all existing user workflows
- ✅ Works with all supported CI systems
Pull Request opened by Augment Code with guidance from the PR author
fyi: The "batch mode" does not only disable interactive prompts but also disables colored log output (ANSI color escape sequences). But some CI-Systems (e.g. GitLab-CI and GitHub Actions) have support for ANSI color escape sequences and can format the log output accordingly. Maybe it's also worth to enable/disable colored output based on the detected CI system.