POC of using Java 15+ sugar for tests.#11537
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 751eba6cd6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
jpbempel
left a comment
There was a problem hiding this comment.
goood idea let's try this while waiting for dropping JDK8 😁
| // gradle/java_no_deps.gradle (which sets options.release in its own configureEach). configureEach | ||
| // actions run at task realization in registration order, so registering last lets us win and | ||
| // clear the release flag — Frgaal needs source > target, which --release forbids. | ||
| project.afterEvaluate { |
There was a problem hiding this comment.
issue: project.afterEvaluate looks wrong, at this point I'm not sure if there's a better approach with frgaal.
| /** | ||
| * Tell IntelliJ (via its Gradle import) that the module accepts Java 17 source while still | ||
| * targeting Java 8 bytecode, matching what Frgaal does for the test compile tasks. Without this | ||
| * the IDE imports the module's language level/SDK from the `java` extension (Java 8) and flags | ||
| * text blocks and other modern syntax as errors. | ||
| */ | ||
| private fun configureIdeaLanguageLevel(project: Project) { | ||
| project.pluginManager.apply("idea") | ||
| project.extensions.configure<IdeaModel>("idea") { | ||
| module.jdkName = SOURCE_VERSION.majorVersion | ||
| module.languageLevel = IdeaLanguageLevel("JDK_${SOURCE_VERSION.majorVersion}") | ||
| module.targetBytecodeVersion = TARGET_VERSION | ||
| } | ||
| } |
There was a problem hiding this comment.
issue: Wouldn;t this bump the language level of the main source set as well ?
| } | ||
|
|
||
| private fun isTestJavaCompileTask(taskName: String): Boolean { | ||
| return taskName == "compileTestJava" || |
There was a problem hiding this comment.
note: this is covered by the check below
| * - **No incremental compilation.** Forking with a custom `javac` executable opts out of Gradle's | ||
| * incremental Java compiler, so affected test source sets always recompile in full. Acceptable for | ||
| * a handful of modules; measure before applying repo-wide. |
There was a problem hiding this comment.
issue: Given the number of tests we have, this could be a noticeable performance regression.
bric3
left a comment
There was a problem hiding this comment.
It certainly seems like an interesting thing to look at, but I believe that in it's current form, using frgaal has quite a few drawbacks.
What Does This Do
POC to investigate if we can improve readability of tests by using syntax sugar from modern Java while still compiling
test classes to Java 8 bytecode using https://frgaal.org.
Only ONE test updated to show how it will be.
Motivation
Many tests contain payload-heavy setup code, string concatenation for JSON/XML, simple dispatch switches, and casts that are harder to read than the behavior being tested. This POC explores using Frgaal for test sources only, so tests can use selected modern Java syntax while keeping the bytecode target compatible with Java 8.
case ->instanceofpattern variablesvarAdditional Notes
This is intentionally very limited: it is literally syntax sugar for test readability. Advanced modern Java features are
not part of this POC and should not be treated as generally available, especially features with runtime semantics such
as records, sealed classes, record patterns, preview features, module imports, or compact source files.