Skip to content

Commit

Permalink
Merge pull request #71 from zbynek/toolchain
Browse files Browse the repository at this point in the history
Allow using Java version from toolchain
  • Loading branch information
jiakuan committed Sep 8, 2023
2 parents 16a93ba 14f63d5 commit a2b56ef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions doc/setup-and-configuration/Configuration References.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 102,18 @@ gwt {
}
```

### Use JVM from Gradle's Java toolchain

In case you are specifying a [Java toolchain](https://docs.gradle.org/current/userguide/toolchains.html)
to compile your Java files with a higher version of Java than the one running Gradle, GWT compilation might fail.
To avoid this you can align the Java versions use for Java and GWT compilation using

```
gwt {
useToolchain = true
}
```

### Log level

The log level of GWT tasks is automatically configured depending on Gradle's log level. So by default this is "ERROR".
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 1 @@
version = 1.1.27
version = 1.1.27
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 24,18 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.TaskAction;
import org.gradle.jvm.toolchain.JavaLauncher;
import org.gradle.jvm.toolchain.JavaToolchainService;
import org.gradle.process.ExecResult;
import org.gradle.process.JavaExecSpec;
import org.docstr.gradle.plugins.gwt.internal.GwtVersion;

/**
Expand Down Expand Up @@ -76,6 80,8 @@ public abstract class AbstractGwtActionTask extends DefaultTask {

private MethodNameDisplayMode methodNameDisplayMode;

private boolean useToolchain;

public AbstractGwtActionTask(String main) {
this.main = main;
}
Expand Down Expand Up @@ -119,6 125,9 @@ public void exec() {
} else {
javaExecSpec.setClasspath(classpath);
}
if (useToolchain) {
setExecutableFromToolchain(javaExecSpec);
}

argIfSet("-XjsInteropMode", getJsInteropMode());
if (doesSupportJsInteropExports(GwtVersion.parse(getGwtVersion()))) {
Expand Down Expand Up @@ -329,6 338,15 @@ public boolean isDebug() {
return debug;
}

@Input
public boolean isUseToolchain() {
return useToolchain;
}

public void setUseToolchain(boolean useToolchain) {
this.useToolchain = useToolchain;
}

/**
* If set to true this enables debugging for the spawned java process.
*
Expand Down Expand Up @@ -408,4 426,13 @@ public void setMethodNameDisplayMode(
MethodNameDisplayMode methodNameDisplayMode) {
this.methodNameDisplayMode = methodNameDisplayMode;
}

private void setExecutableFromToolchain(JavaExecSpec javaExecSpec) {
JavaPluginExtension extension = getProject().getExtensions()
.getByType(JavaPluginExtension.class);
JavaLauncher javaLauncher = getProject().getExtensions().getByType(JavaToolchainService.class)
.launcherFor(extension.getToolchain()).get();
String defaultLauncher = javaLauncher.getExecutablePath().toString();
javaExecSpec.setExecutable(defaultLauncher);
}
}

0 comments on commit a2b56ef

Please sign in to comment.