GROOVY-12204: Support check-only compilation (stop after a configurab… - #2741
GROOVY-12204: Support check-only compilation (stop after a configurab…#2741paulk-asert wants to merge 1 commit into
Conversation
…le compile phase) Add a targetPhase property to CompilerConfiguration (default Phases.ALL) which the no-arg CompilationUnit.compile() now honors; callers that name an explicit phase, such as the AST browser, are unaffected. The new groovyc --check option is sugar for setting the target phase to INSTRUCTION_SELECTION: parse, resolution, and static type-checking errors are still reported but no class files are generated, giving a faster feedback loop for editors, CI checks, and coding agents.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2741 +/- ##
==================================================
- Coverage 69.8687% 69.8658% -0.0028%
- Complexity 35137 35140 +3
==================================================
Files 1554 1554
Lines 130731 130742 +11
Branches 23916 23917 +1
==================================================
+ Hits 91340 91344 +4
- Misses 31145 31150 +5
- Partials 8246 8248 +2
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 7ddf90a Learn more about TestLens at testlens.app. |
There was a problem hiding this comment.
⚠️ Not ready to approve
The user-facing --check help/docs text claims compilation stops “after static analysis” even though the configured phase is INSTRUCTION_SELECTION (part of class generation), so the wording should be corrected to avoid misleading users.
Pull request overview
Adds “check-only” compilation support to Groovy by introducing a configurable target compilation phase, enabling groovyc --check to validate sources (including static type-checking errors) without producing .class files.
Changes:
- Add
targetPhasetoCompilerConfiguration(defaultPhases.ALL) and make no-argCompilationUnit.compile()honor it. - Add
groovyc --checkCLI option that sets the target phase toPhases.INSTRUCTION_SELECTIONto suppress class file output. - Add tests and update the groovyc documentation to cover the new behavior.
File summaries
| File | Description |
|---|---|
| src/test/groovy/org/codehaus/groovy/tools/FileSystemCompilerTest.java | Adds integration tests ensuring check-only compilation suppresses class files and still reports type errors; verifies --check behavior. |
| src/test/groovy/org/codehaus/groovy/control/CompilerConfigurationTest.java | Adds unit tests for defaulting, clamping, copying, and immutability of the new targetPhase setting. |
| src/spec/doc/tools-groovyc.adoc | Documents the new --check command-line option. |
| src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java | Introduces the --check CLI flag and maps it to CompilerConfiguration#setTargetPhase(...). |
| src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java | Introduces targetPhase property with getters/setters and ensures it’s copied and immutable on DEFAULT. |
| src/main/java/org/codehaus/groovy/control/CompilationUnit.java | Updates no-arg compile() to compile up to the configured target phase. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Low
Note
Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.
| @Option(names = {"--check"}, description = "Check sources for errors without generating class files (stops compilation after static analysis)") | ||
| private boolean checkOnly; |
| | | --encoding | Encoding of the source files | groovyc --encoding utf-8 script.groovy | ||
| | | --help | Displays help for the command line groovyc tool | groovyc --help | ||
| | -d | | Specify where to place generated class files. | groovyc -d target Person.groovy | ||
| | | --check | Check sources for errors without generating class files (stops compilation after static analysis) | groovyc --check Person.groovy |
…le compile phase) https://issues.apache.org/jira/browse/GROOVY-12204
Add a targetPhase property to CompilerConfiguration (default Phases.ALL) which the no-arg CompilationUnit.compile() now honors; callers that name an explicit phase, such as the AST browser, are unaffected. The new groovyc --check option is sugar for setting the target phase to INSTRUCTION_SELECTION: parse, resolution, and static type-checking errors are still reported but no class files are generated, giving a faster feedback loop for editors, CI checks, and coding agents.