Run Kotlin tests for target 1.8 By default, the Kotlin compiler generates classes for target 1.6. This CL updates the build.gradle file to also build classes for target 1.8. Also updates parameters of R8 Kotlin tests to run on 1.8 classes. Bug: 71894643 Change-Id: I9fafc642dc2d422fff721c3d592c6884d8503fbb
diff --git a/buildSrc/src/main/java/kotlin/Kotlinc.java b/buildSrc/src/main/java/kotlin/Kotlinc.java index 261acc3..0c0a50a 100644 --- a/buildSrc/src/main/java/kotlin/Kotlinc.java +++ b/buildSrc/src/main/java/kotlin/Kotlinc.java
@@ -19,16 +19,29 @@ import utils.Utils; /** - * Gradle task to compile Kotlin source files. + * Gradle task to compile Kotlin source files. By default the generated classes target Java 1.6. */ public class Kotlinc extends DefaultTask { + enum KotlinTargetVersion { + JAVA_6("1.6"), + JAVA_8("1.8"); + + private final String optionName; + + KotlinTargetVersion(String optionName) { + this.optionName = optionName; + } + } + @InputFiles private FileTree source; @OutputFile private File destination; + private KotlinTargetVersion targetVersion = KotlinTargetVersion.JAVA_6; + public FileTree getSource() { return source; } @@ -45,6 +58,14 @@ this.destination = destination; } + public KotlinTargetVersion getTargetVersion() { + return targetVersion; + } + + public void setTargetVersion(KotlinTargetVersion targetVersion) { + this.targetVersion = targetVersion; + } + @TaskAction public void compile() { getProject().exec(new Action<ExecSpec>() { @@ -57,6 +78,7 @@ execSpec.setExecutable(kotlincExecPath.toFile()); execSpec.args("-include-runtime"); execSpec.args("-nowarn"); + execSpec.args("-jvm-target", targetVersion.optionName); execSpec.args("-d", destination.getCanonicalPath()); execSpec.args(source.getFiles()); } catch (IOException e) {