javac "--release" Flag Mismatch With source/target - Fix in CI
javac rejected the combination of --release with --source/--target. The two cross-compilation schemes are mutually exclusive; the build configured both.
What this error means
Compilation fails immediately with option --release cannot be used together with --source or --target. The error is about flag combination, not your code.
error: option --release cannot be used together with --source or --target
Usage: javac <options> <source files>Common causes
Both release and source/target configured
Setting maven.compiler.release while also setting maven.compiler.source/target (or release plus sourceCompatibility/targetCompatibility in Gradle) passes both flag families to javac, which is illegal.
Inherited config collides with a new release setting
A parent POM or convention plugin sets source/target while the module adds release, producing the conflict at compile time.
How to fix it
Use release only (Maven)
Prefer maven.compiler.release; remove source/target so only one scheme is passed.
<properties>
<maven.compiler.release>17</maven.compiler.release>
<!-- remove maven.compiler.source and maven.compiler.target -->
</properties>Use one scheme (Gradle)
Set the release via the compiler options and drop sourceCompatibility/targetCompatibility, or vice versa.
tasks.withType<JavaCompile> {
options.release.set(17)
}
// do not also set sourceCompatibility / targetCompatibilityHow to prevent it
- Standardize on
--releaseeverywhere and remove source/target, checking parent POMs and convention plugins for inherited settings.