diff --git a/src/main/java/org/gradle/playframework/plugins/PlayTwirlPlugin.java b/src/main/java/org/gradle/playframework/plugins/PlayTwirlPlugin.java index 36ecf6b6..4b6f68d8 100644 --- a/src/main/java/org/gradle/playframework/plugins/PlayTwirlPlugin.java +++ b/src/main/java/org/gradle/playframework/plugins/PlayTwirlPlugin.java @@ -9,7 +9,9 @@ import org.gradle.playframework.sourcesets.TwirlSourceSet; import org.gradle.playframework.sourcesets.internal.DefaultTwirlSourceSet; import org.gradle.playframework.tasks.TwirlCompile; +import org.gradle.playframework.tasks.TwirlCompileExt; import org.gradle.playframework.tools.internal.twirl.TwirlCompilerFactory; +import org.gradle.util.GradleVersion; import java.util.List; @@ -56,7 +58,13 @@ private void declareDefaultDependencies(Project project, Configuration configura } private TaskProvider createDefaultTwirlCompileTask(Project project, TwirlSourceSet twirlSourceSet, Configuration compilerConfiguration, PlayExtension playExtension) { - return project.getTasks().register(TWIRL_COMPILE_TASK_NAME, TwirlCompile.class, twirlCompile -> { + Class type; + if (GradleVersion.current().compareTo(GradleVersion.version("6.7")) < 0) { + type = TwirlCompile.class; + } else { + type = TwirlCompileExt.class; + } + return project.getTasks().register(TWIRL_COMPILE_TASK_NAME, (Class) type, twirlCompile -> { twirlCompile.setDescription("Compiles Twirl templates for the '" + twirlSourceSet.getTwirl().getDisplayName() + "' source set."); twirlCompile.getPlatform().set(project.provider(() -> playExtension.getPlatform())); twirlCompile.setSource(twirlSourceSet.getTwirl()); diff --git a/src/main/java/org/gradle/playframework/tasks/TwirlCompile.java b/src/main/java/org/gradle/playframework/tasks/TwirlCompile.java index 07b9a648..9ea5d1ad 100644 --- a/src/main/java/org/gradle/playframework/tasks/TwirlCompile.java +++ b/src/main/java/org/gradle/playframework/tasks/TwirlCompile.java @@ -2,7 +2,6 @@ import org.gradle.api.Action; import org.gradle.api.file.ConfigurableFileCollection; -import org.gradle.api.file.Directory; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.FileTree; import org.gradle.api.file.FileVisitDetails; @@ -111,6 +110,10 @@ public ConfigurableFileCollection getTwirlCompilerClasspath() { return twirlCompilerClasspath; } + protected String executable() { + return null; + } + @TaskAction @SuppressWarnings("Convert2Lambda") void compile() { @@ -121,7 +124,13 @@ void compile() { if (GradleVersion.current().compareTo(GradleVersion.version("5.6")) < 0) { workerExecutor.submit(TwirlCompileRunnable.class, workerConfiguration -> { workerConfiguration.setIsolationMode(IsolationMode.PROCESS); - workerConfiguration.forkOptions(options -> options.jvmArgs("-XX:MaxMetaspaceSize=256m")); + workerConfiguration.forkOptions(options -> { + options.jvmArgs("-XX:MaxMetaspaceSize=256m"); + String executable = executable(); + if (executable != null) { + options.setExecutable(executable); + } + }); workerConfiguration.params(spec, getCompiler()); workerConfiguration.classpath(twirlCompilerClasspath); workerConfiguration.setDisplayName("Generating Scala source from Twirl templates"); @@ -130,7 +139,13 @@ void compile() { WorkQueue workQueue = workerExecutor.processIsolation(new Action() { @Override public void execute(ProcessWorkerSpec workerSpec) { - workerSpec.forkOptions(options -> options.jvmArgs("-XX:MaxMetaspaceSize=256m")); + workerSpec.forkOptions(options -> { + options.jvmArgs("-XX:MaxMetaspaceSize=256m"); + String executable = executable(); + if (executable != null) { + options.setExecutable(executable); + } + }); workerSpec.getClasspath().from(twirlCompilerClasspath); } }); diff --git a/src/main/java/org/gradle/playframework/tasks/TwirlCompileExt.java b/src/main/java/org/gradle/playframework/tasks/TwirlCompileExt.java new file mode 100644 index 00000000..17226d68 --- /dev/null +++ b/src/main/java/org/gradle/playframework/tasks/TwirlCompileExt.java @@ -0,0 +1,35 @@ +package org.gradle.playframework.tasks; + +import org.gradle.api.Incubating; +import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Internal; +import org.gradle.jvm.toolchain.JavaLauncher; +import org.gradle.workers.WorkerExecutor; + +import javax.inject.Inject; + +public class TwirlCompileExt extends TwirlCompile { + @Inject + public TwirlCompileExt(WorkerExecutor workerExecutor) { + super(workerExecutor); + this.javaLauncher = getProject().getObjects().property(JavaLauncher.class); + } + + private final Property javaLauncher; + + /** + * The toolchain {@link JavaLauncher} to use for executing the twirl template compiler. + * + * @return the java launcher property + */ + @Internal + @Incubating + public Property getJavaLauncher() { + return this.javaLauncher; + } + + @Override + protected String executable() { + return getJavaLauncher().map(launcher -> launcher.getExecutablePath().getAsFile().getAbsolutePath()).getOrNull(); + } +}