apache / apache/maven-apache-parent

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

Open
#608 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
No language data
Stars
48
Forks
34
Avg merge
1d 8h
Merged PRs (30d)
4

Description

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 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 (apache/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](https://issues.apache.org/jira/browse/FLINK-40630).

*This issue was created with AI assistance.*

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the jdk9+ profile and its maven.compiler.release configuration, then review the parent’s release notes, site, and enforcer execution. Reproduce the mismatch using a child that sets source and target without release, and determine how the documented guidance or loud failure should cover it. Done means the silent downgrade is addressed and the child configuration behavior is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.