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

Default to the current Java version #115

Merged
merged 1 commit into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Default to the current Java version
This is a workaround for Gradle < 7 not being able to set the vendor
requirement, which causes hard to diagnose errors.

Fixes #109
  • Loading branch information
melix committed Aug 9, 2021
commit da660b3ac244a5b89e57da50df05b01e9fb318db
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.graalvm.buildtools.gradle


import org.gradle.testkit.runner.GradleRunner
import spock.lang.Issue
import spock.lang.Specification
import spock.lang.TempDir

import java.nio.file.Path

class NativeImageOptionsTest extends Specification {
@TempDir
Path testDirectory

@Issue("https://github.com/graalvm/native-build-tools/issues/109")
def "toolchain defaults to the current Java version"() {
when:
def runner = GradleRunner.create()
.forwardStdOutput(new PrintWriter(System.out))
.forwardStdError(new PrintWriter(System.err))
.withPluginClasspath()
.withProjectDir(testDirectory.toFile())


def buildFile = testDirectory.resolve("build.gradle")
buildFile.text = """
plugins {
id 'java'
id 'org.graalvm.buildtools.native'
}

assert nativeBuild.javaLauncher
.get()
.metadata
.languageVersion
.toString() == JavaVersion.current().majorVersion
"""

runner.build()

then:
noExceptionThrown()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import org.graalvm.buildtools.gradle.internal.GradleUtils;
import org.gradle.api.Action;
import org.gradle.api.JavaVersion;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.model.ObjectFactory;
Expand Down Expand Up @@ -210,7 +211,7 @@ public NativeImageOptions(ObjectFactory objectFactory,
getImageName().convention(defaultImageName);
getJavaLauncher().convention(
toolchains.launcherFor(spec -> {
spec.getLanguageVersion().set(JavaLanguageVersion.of(11));
spec.getLanguageVersion().set(JavaLanguageVersion.of(JavaVersion.current().getMajorVersion()));
if (GradleUtils.isAtLeastGradle7()) {
spec.getVendor().set(JvmVendorSpec.matching("GraalVM"));
}
Expand Down