Skip to content

Conversation

@gnodet
Copy link
Contributor

@gnodet gnodet commented Oct 15, 2025

The pom does not define maven.compiler.source and maven.compiler.target anymore

The pom does not define maven.compiler.source and maven.compiler.target anymore
<jdk>[,9)</jdk>
</activation>
<properties>
<maven.compiler.source>${maven.compiler.target}</maven.compiler.source>
Copy link
Contributor

@Bukama Bukama Oct 15, 2025

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

We cannot mix -source and --release when invoking javac (tool documentation). The version 3 of the compiler plugin had some build-in logic for choosing which option to use. But in version 4, this logic has been removed. The rational are:

  • One goal of version 4 of the compiler plugin is to reduce the amount of heuristic rules and be more straightforward in the arguments passed to javac.
  • Since Maven 4 can be executed only on Java 17 or later, the --release option can be used unconditionally, except when using toolchains or forked compiler. So we could start forgetting about -source.
  • There is a risk of ambiguity if both <release> and <source> are specified with inconsistent values. I presume that this is the reason why javac rejects the case where the two options are specified.

Copy link
Member

@kwin kwin Oct 20, 2025

Choose a reason for hiding this comment

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

@desruisseaux

The --release option is not supported using JDK 8. However, since Compiler plugin version 3.13.0 you can use the release property also on JDK 8. The plugin will convert it to source and target automatically.

(from https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html#Usage_on_JDK_8)

For m-compiler-p 4.xx requiring Java 17+ this profile is anyhow not relevant.

Copy link
Member

Choose a reason for hiding this comment

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

Not sure about m-javadoc-p though as that evaluates the same properties...

Choose a reason for hiding this comment

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

@kwin : the documentation that you cite is specific to Maven Compiler Plugin 3.x. It is not standard Java and does not apply anymore to Maven Compiler Plugin 4.x.

@gnodet gnodet added breaking Pull requests that break existing features enhancement New feature or request labels Oct 16, 2025
<properties>
<!-- https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-release.html, affects m-compiler-p and m-javadoc-p -->
<maven.compiler.release>${maven.compiler.target}</maven.compiler.release>
<maven.compiler.release>8</maven.compiler.release>
Copy link
Member

Choose a reason for hiding this comment

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

why hardcoded to 8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's the current default value. My aim was to have a similar behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Have you tried overwriting this in a child outside a profile. Not sure which one takes precedence to be honest: https://maven.apache.org/guides/introduction/introduction-to-profiles.html#Profile_Order

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The child always takes precedence over the parent, parent profiles included.

@slawekjaranowski
Copy link
Member

@gnodet we need update documentation:

** The compiler plugin is set target <<Java $context.get("maven.compiler.target")>> (<<<maven.compiler.target>>> property)
and assume $context.get("project.build.sourceEncoding") source encoding (<<<project.build.sourceEncoding>>> property). When being executed
with JDK 9 or newer also <<<maven.compiler.release>>> is set to the value of property <<<maven.compiler.target>>>.
Therefore its value must not start with <<<1.>>> (use for example <<<8>>> instead of <<<1.8>>>).

@gnodet gnodet added this to the ASF-36 milestone Nov 10, 2025
@slachiewicz

This comment was marked as outdated.

@slawekjaranowski
Copy link
Member

Ok, child project should be simple as possible
How we provide a way to say in child project that want to use eg JDK 17 as target?

@slawekjaranowski
Copy link
Member

Maybe we need a new property - like javaVersion and child project can set it if needed

@desruisseaux
Copy link

You can also set target.release to 8 for Java 8 - compiler plugin should ignore it

Not the Maven 4.0.0-beta-3 plugin. It will raise an error. Actually it will forward the parameter verbatim to javac, and javac will raise an error.

@slawekjaranowski
Copy link
Member

You can also set target.release to 8 for Java 8 - compiler plugin should ignore it

Not the Maven 4.0.0-beta-3 plugin. It will raise an error. Actually it will forward the parameter verbatim to javac, and javac will raise an error.

so it is next reason to introduce new property for java version for child projects.
and maven.compiler.* should be set only here and not touched in child projects

@desruisseaux
Copy link

Well, my comment was inexact. Maven 4 requires Java 17+, and Java 17 accepts --release 8. So no error should be raised by javac (until Java 8 is not supported anymore).

@slachiewicz
Copy link
Member

see some challenges apache/maven-compiler-plugin#990

@gnodet
Copy link
Contributor Author

gnodet commented Nov 10, 2025

see some challenges apache/maven-compiler-plugin#990

One can still set the maven.compiler.source to 8 when needed.
Are you worried about compatibility ? This is flagged as breaking.

@gnodet gnodet merged commit 2d0578a into apache:master Nov 13, 2025
3 checks passed
@slawekjaranowski
Copy link
Member

see some challenges apache/maven-compiler-plugin#990

One can still set the maven.compiler.source to 8 when needed. Are you worried about compatibility ? This is flagged as breaking.

Ok no worry about break changes ...

But if child project override maven.compiler.source we will brek what we want here - only use maven.compiler.release

And should be documented which property should be override be child project to select proper target

gnodet added a commit to gnodet/maven-parent that referenced this pull request Nov 13, 2025
Defining maven.compiler.source and maven.compiler.target properties when
running on JDK >= 9 has some side effects.

Fixes apache#503

Follow-up to apache/maven-apache-parent#543 and apache/maven-apache-parent#550
slawekjaranowski added a commit to apache/maven-parent that referenced this pull request Nov 15, 2025
* Enhance target JDK definition for JDK >= 1

Defining maven.compiler.source and maven.compiler.target properties when
running on JDK >= 9 has some side effects.

Fixes #503

Follow-up to apache/maven-apache-parent#543 and apache/maven-apache-parent#550

* use javaVersion property

---------

Co-authored-by: Slawomir Jaranowski <[email protected]>
Copy link
Member

@ctubbsii ctubbsii left a comment

Choose a reason for hiding this comment

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

I'm in favor of only defining the release property, and not source and target on newer JDKs, but this will probably break some people. A lot of plugins that do code generation, source formatting, etc., rely on the source/target properties to control their behavior, and not all of them have been updated to understand the release property. So, while this is completely fine for the compiler plugin, users should be aware that it may have unintended consequences for other plugins.

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

Labels

breaking Pull requests that break existing features enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants