-
Notifications
You must be signed in to change notification settings - Fork 28
Switch JDK >= 9 to only use maven.compiler.release #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Afaik the compiler plugin handles this itself, so you can always use release, doesn't it?
There was a problem hiding this comment.
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
--releaseoption 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 whyjavacrejects the case where the two options are specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
For m-compiler-p 4.xx requiring Java 17+ this profile is anyhow not relevant.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
| <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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why hardcoded to 8?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
@gnodet we need update documentation: maven-apache-parent/docs/src/site/apt/index.apt.vm Lines 80 to 83 in cdf6781
|
This comment was marked as outdated.
This comment was marked as outdated.
|
Ok, child project should be simple as possible |
|
Maybe we need a new property - like |
Not the Maven 4.0.0-beta-3 plugin. It will raise an error. Actually it will forward the parameter verbatim to |
so it is next reason to introduce new property for java version for child projects. |
|
Well, my comment was inexact. Maven 4 requires Java 17+, and Java 17 accepts |
|
see some challenges apache/maven-compiler-plugin#990 |
One can still set the |
Ok no worry about break changes ... But if child project override And should be documented which property should be override be child project to select proper target |
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
* 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]>
ctubbsii
left a comment
There was a problem hiding this 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.
The pom does not define maven.compiler.source and maven.compiler.target anymore