Skip to content

jdk9+ profile replaces a child's source and target with release 8 #608

Description

@slachiewicz

Since 36 (#543, #551) the jdk9+ profile sets maven.compiler.release to ${javaVersion}, which defaults to 8. Parents 32 to 35 derived it from maven.compiler.target instead, so overriding target in a child still took effect there. maven-compiler-plugin gives release precedence over source/target (plexus-compiler emits --release whenever the value is non-empty), so a child POM that declares maven.compiler.source and maven.compiler.target but no release, which is every child written against a parent before 32, is compiled for Java 8 on JDK 9+ regardless of its own settings.

Observed on flink-connector-parent moving from org.apache:apache:20 to 39 with source 11 / target 17:

[INFO] Compiling 130 source files with javac [debug release 8] to target/classes
[ERROR] TransactionOwnership.java:[74,29] method orElseThrow in class java.util.Optional<T> cannot be applied to given types

The compile error is the good outcome. A child whose sources happen to be Java 8 compatible is silently downgraded to bytecode 52 instead.

Each available workaround has a cost:

  • Setting javaVersion fixes release, but it is a single value. A child with different source and target levels, or with per-profile targets, cannot express that through --release.
  • Blanking maven.compiler.release restores -source/-target for javac, but maven-javadoc-plugin fails on the empty string (Empty release value fails with StringIndexOutOfBoundsException maven-javadoc-plugin#1376).
  • Overriding the compiler plugin's release parameter in the child works, but nothing points a user at it.

A POM profile cannot see whether the child set maven.compiler.source, so the profile itself cannot be made conditional. What would help:

  1. Call this out in the release notes and on the parent's site: a child that sets maven.compiler.source/target must also set javaVersion or override maven.compiler.release, or its levels are ignored.
  2. Consider having the parent's enforcer execution fail when maven.compiler.source or maven.compiler.target differs from javaVersion on JDK 9+, so the mismatch fails loudly instead of downgrading silently.

Context: FLINK-40630.

This issue was created with AI assistance.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions