Skip to content

Read Spoon compliance level from the project's pom.xml - #352

Open
CatarinaGamboa wants to merge 3 commits into
mainfrom
fix/compliance-level
Open

CatarinaGamboa wants to merge 3 commits into
mainfrom
fix/compliance-level

Conversation

@CatarinaGamboa

@CatarinaGamboa CatarinaGamboa commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

CommandLineLauncher sets Spoon's compliance level to 8, so any Java 9+ syntax fails to compile and LiquidJava verifies a broken model with only a generic warning ("Java compilation encountered issues"). E.g. var n = 5; is read as a variable of class testSuite.var (Sorts testSuite.var and Int are incompatible), and try (r) (Java 9 resource reference) does not parse, which blocks the second reproducer of #334.

Change

  • New ComplianceLevel reads the level from the maven.compiler.release (or maven.compiler.source) property of the nearest pom.xml of each verified path, walking up to enclosing poms, using the existing maven-model dependency. 1.8 is read as 8; with several paths the highest level wins.
  • Defaults to 19 when no pom declares it, and caps at 19: the highest level Spoon 10.4.2's JDT (3.33) accepts (20 throws Unrecognized option : -20). The cap is silent (the level is printed with --debug), since e.g. liquidjava-example declares 20 and a warning would show up on every run.
  • New test CorrectModernJavaSyntax (var, try (r), switch expression): fails at level 8, passes now.
  • Unit tests TestComplianceLevel (reads the pom, caps).

Not read (falls back to 19): the compiler plugin's <release>/<source> config, parents outside the enclosing directories, Gradle builds. Upgrading to Spoon 11.5 (levels up to 26) is in #363.

Testing

mvn test: 369/369 pass.

🤖 Generated with Claude Code

At level 8, Java 9+ syntax (`var`, `try (r)`, switch expressions) fails to
compile, so verification runs on a broken model (e.g. `var` becomes a class
`testSuite.var`). 17 is the highest level Spoon 10.4.2's JDT accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alcides

alcides commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Should this be a cli flag? or read from maven?

@CatarinaGamboa

Copy link
Copy Markdown
Collaborator Author

I can check that but im not sure if all versions are supported by spoon

Spoon's compliance level is now taken from the nearest pom.xml of the
verified paths (compiler plugin release/source, then the
maven.compiler.release/source properties, walking up to enclosing poms).
It defaults to 19 when no pom declares one and is capped at 19, the
highest level Spoon 10.4.2's JDT accepts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CatarinaGamboa CatarinaGamboa added the dependencies Pull requests that update a dependency file label Oct 7, 2026
@CatarinaGamboa CatarinaGamboa changed the title Raise Spoon compliance level from 8 to 17 Read Spoon compliance level from the project's pom.xml Oct 7, 2026
return Optional.empty();
}
}
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this file is HUGE for what it is doing, I trust that you can make something much much more contained! We can also import something to read the POM if needed, im sure there are libraries for that

writePom(project, "<maven.compiler.release>25</maven.compiler.release>", null);
assertEquals(ComplianceLevel.MAX_SUPPORTED, ComplianceLevel.resolve(source().toString()));
}
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

we dont need as many tests i believe

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants