Skip to content
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

JavaCompile and Test tasks silently ignore explicit executable if it does not exist #21758

Closed
alllex opened this issue Aug 31, 2022 · 0 comments
Assignees
Labels
a:bug in:toolchains Java Toolchains @support Issues owned by GBT support team
Milestone

Comments

@alllex
Copy link
Member

alllex commented Aug 31, 2022

When resolving which toolchain to use for the java compiler in the JavaCompile task or for the launcher in the Test task, there is a priority that is given to an executable path explicitly set via fork options. However, if a user makes a mistake by providing a wrong path, then the provided value is silently ignored and the current toolchain is used to execute the work.

At the very least, the user should be warned about this. However, being strict about this may be better, as this can be overlooked when tasks are running on CI and for some reason it was required to use an explicit path, rather than resolving a toolchain.

final String customExecutable = getOptions().getForkOptions().getExecutable();
if (customExecutable != null) {
final File executable = new File(customExecutable);
if (executable.exists()) {
// Relying on the layout of the toolchain distribution: <JAVA HOME>/bin/<executable>
File parentJavaHome = executable.getParentFile().getParentFile();
return new SpecificInstallationToolchainSpec(objectFactory, parentJavaHome);
}
}

@jbartok jbartok added in:toolchains Java Toolchains and removed to-triage labels Sep 2, 2022
@jbartok jbartok added this to the 7.6 RC1 milestone Sep 2, 2022
@jbartok jbartok self-assigned this Sep 2, 2022
@ljacomet ljacomet assigned ljacomet and unassigned jbartok Sep 2, 2022
@ljacomet ljacomet added the @support Issues owned by GBT support team label Sep 5, 2022
ljacomet added a commit that referenced this issue Sep 14, 2022
When configuring the executable on JavaCompile or Test, if it points to
a non-existing file, Gradle now fails with an error.

Fixes #21758
bot-gradle added a commit that referenced this issue Sep 15, 2022
When configuring the executable on JavaCompile or Test, if it points to a non-existing file, Gradle now fails with an error.

Fixes #21758

Co-authored-by: Louis Jacomet <louis@gradle.com>
xaviarias added a commit that referenced this issue Oct 11, 2022
Extracted duplicate behaviour into a factory method containing additional validations for consistency, i.e. the executable exists and is not a directory.

Fixes: #22023
See also: #21758

Add tests for missing validation cases

The following tests have been added both for `JavaCompile` and `Test` tasks:

 - Custom Java home does not exist
 - Custom Java home is not a directory
 - Custom Java home is not a valid JVM
 - Custom executable is not from a valid JVM

For the last two tests, `JavaToolchainQueryService` has been updated to throw an exception when the JVM specific toolchain is not valid.
bot-gradle added a commit that referenced this issue Nov 11, 2022
…tion

Extracted duplicate behaviour into a factory method containing additional validations for consistency, i.e. the executable exists and is not a directory.

Fixes: #22023
See also: #21758

Co-authored-by: @jbartok

**NOTE:** This PR will remain a draft until #22108 is merged in and then needs to be adapted to those changes.

Co-authored-by: Xavier Arias Seguí <xavier.arias.segui@gradle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug in:toolchains Java Toolchains @support Issues owned by GBT support team
Projects
None yet
Development

No branches or pull requests

3 participants