Skip to content

GROOVY-12204: Support check-only compilation (stop after a configurab… - #2741

Open
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12204
Open

GROOVY-12204: Support check-only compilation (stop after a configurab…#2741
paulk-asert wants to merge 1 commit into
apache:masterfrom
paulk-asert:groovy12204

Conversation

@paulk-asert

@paulk-asert paulk-asert commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

…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.

…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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.8658%. Comparing base (023b9f5) to head (7ddf90a).

Additional details and impacted files

Impacted file tree graph

@@                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     
Files with missing lines Coverage Δ
...a/org/codehaus/groovy/control/CompilationUnit.java 80.7453% <100.0000%> (ø)
...codehaus/groovy/control/CompilerConfiguration.java 74.3671% <100.0000%> (+0.7515%) ⬆️
.../org/codehaus/groovy/tools/FileSystemCompiler.java 50.9524% <100.0000%> (+0.4716%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Jul 28, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 7ddf90a
▶️ Tests: 106167 executed
⚪️ Checks: 31/31 completed


Learn more about TestLens at testlens.app.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 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 targetPhase to CompilerConfiguration (default Phases.ALL) and make no-arg CompilationUnit.compile() honor it.
  • Add groovyc --check CLI option that sets the target phase to Phases.INSTRUCTION_SELECTION to 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.

Comment on lines +560 to +561
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants