[ 
https://issues.apache.org/jira/browse/MCOMPILER-533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17799540#comment-17799540
 ] 

Jorge Solórzano commented on MCOMPILER-533:
-------------------------------------------

There are some scenarios where it might be useful to have this behavior, some 
projects set source/target to compile to Java 8 and use a profile to compile to 
Java 9 using the -release option.

The error is not lost because Maven gives priority to the -release option, and 
that should be correct, it does not set the source/target so no error occurs.

Yet, I think that a warning should be displayed mentioning that --target is 
ignored when used together with --release if both are set.

> Output an error when --release option is used together with --source or 
> --target
> --------------------------------------------------------------------------------
>
>                 Key: MCOMPILER-533
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-533
>             Project: Maven Compiler Plugin
>          Issue Type: Improvement
>    Affects Versions: 3.11.0
>            Reporter: Arend v. Reinersdorff
>            Priority: Major
>
> javac outputs an error when the --release option is used together with the 
> --source or --target option. See 
> [https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-release]
> For example:
> {{javac --release 17 --target 17 ...}}
> Will fail with this error:
> {{error: option --target cannot be used together with --release}}
> This is nice because it informs the user of misconfiguration and enforces the 
> use of only \-\-release or only \-\-source/--target.
> Unfortunately, the error is lost when compiling with Maven. Maven uses the 
> release option and silently ignores source and target. Users don't notice 
> when they unnecessarily set both. See for example 
> [https://github.com/spring-projects/spring-boot/pull/34761]
> For example:
> {{<plugin>}}
> {{    <groupId>org.apache.maven.plugins</groupId>}}
> {{    <artifactId>maven-compiler-plugin</artifactId>}}
> {{    <version>3.11.0</version>}}
> {{    <configuration>}}
> {{        <release>17</release>}}
> {{        <source>17</source>}}
> {{        <target>17</target>}}
> {{    </configuration>}}
> {{</plugin>}}
> Compiles using the release option without any error or warning.
> It would be nice to restore the error from javac in Maven, or output a 
> similar one.
> The problem I see is that Maven uses default values for source and target. 
> When the user sets only the release option, no error or warning should be 
> caused because of the default values for source and target.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to