Full control over all options given to Java tools #25962
Labels
a:feature
A new functionality
in:java-plugins
java-library, java, java-base, java-platform, java-test-fixtures
in:modular-java
Expected Behavior
When getting a list of compiler arguments with
CompileOptions.getCompilerArgs()
orStandardJavadocDocletOptions
, we can add, remove or edit the arguments to be given tojavac
orjavadoc
. We would expect our arguments to be given verbatim to the Java tools, modulo semantic differences betweengetCompilerArgs()
andgetAllCompilerArgs()
, with no modification added by Gradle after our own modifications. We would also expect to be able to modify all arguments, i.e. the list returned bygetAllCompilerArgs()
.Current Behavior (optional)
Currently the CompilerOptions class has a
getCompilerArgs()
method providing a mutable list, but that list is only for additional options appended after the options managed by Gradle. Attempts to modify the options for fixing the class-path versus module-path issue #25954 do not work fully as expected because:--module-path
in the compiler options cause the option to appear twice in the debug output of Gradle 8.2. The two occurrences have the exact same path, which may be large. We found no way to prevent that duplication, as it does not appear in the list returned by CompilerOptions.getCompilerArgs().--source-path
and--module-source-path
options are mutually exclusive. But Gradle's debug output seems to unconditionally provide the--source-path
option at least with an empty string, because the empty string has a different meaning than the default value. Using the Gradle API for setting the source path to null does not help because Gradle interprets that as an empty path. We saw no API for telling Gradle to omit completely that option. This is a problem because the--module-source-path
option is absolutely necessary for Module Source Hierarchy, and Gradle insistence to add its own options causesjavac
to emit the following: error: cannot specify both--source-path
and--module-source-path
.StandardJavadocDocletOptions
. The class-path was incomplete at the time we wanted to configure the options, and is magically completed later with undesired new entries added after we have set the value that we wanted. This behavior causes Javadoc generation to fail in a Module Source Hierarchy, with no workaround we could find so far.I think that in some cases, developers need a way to have the final word on all options to be given to Java tools (except the list of source files to compile), with the guarantee that the list contains all options that Gradle wanted to provide (no missing class-path entries magically added later), and that Gradle will not apply any further modification to this list. The wish is to avoid any "clever" attempt by Gradle to "help" users with options that Gradle thinks should be added. I saw that there is a
CompilerOptions.getAllCompilerArgs()
method, but unfortunately the returned list is unmodifiable.The reason why full control on all compiler options is sometime desired is because latest Java releases may have new features that are incompatible with the options managed by Gradle. Above issue with
--source-path
versus--module-source-path
is an example. Even if Gradle resolves this incompatibility, other incompatibles options existed in the past (e.g.-release
versus-source
and-target
) and we cannot know in advance what will be the next incompatible options in future Java releases. We may also want to do cleanups such as removing the--module-path
duplication.Context
This issue is part of an effort to migrate the Apache SIS project from Maven to Gradle in order to support Module Source Hierarchy. What is Module Source Hierarchy, and how it worked with Gradle so far, are described in the following document:
The most critical issue is #25954, but the wish expressed in this issue would be a helpful fallback when a standard Java feature is not yet well supported by Gradle.
The text was updated successfully, but these errors were encountered: