1 import org.gradle.api.tasks.InputFile 2 import org.gradle.api.tasks.InputFiles 3 import org.gradle.api.tasks.JavaExec 4 import org.gradle.api.tasks.OutputDirectory 5 import org.gradle.api.tasks.bundling.Zip 6 import org.gradle.kotlin.dsl.get 7 import org.gradle.kotlin.dsl.named 8 import java.io.File 9 10 /* 11 * Task used by our ui/android tests to test minification results 12 * and keep track of size of the binary. 13 * TODO move back to kotlinx-coroutines-android when it's migrated to the kts 14 */ 15 open class RunR8 : JavaExec() { 16 17 @OutputDirectory 18 lateinit var outputDex: File 19 20 @InputFile 21 lateinit var inputConfig: File 22 23 @InputFile 24 val inputConfigCommon: File = File("testdata/r8-test-common.pro") 25 26 @InputFiles 27 val jarFile: File = project.tasks.named<Zip>("jar").get().archivePath 28 29 init { 30 classpath = project.configurations["r8"] 31 main = "com.android.tools.r8.R8" 32 } 33 execnull34 override fun exec() { 35 // Resolve classpath only during execution 36 val arguments = mutableListOf( 37 "--release", 38 "--no-desugaring", 39 "--output", outputDex.absolutePath, 40 "--pg-conf", inputConfig.absolutePath 41 ) 42 arguments.addAll(project.configurations["runtimeClasspath"].files.map { it.absolutePath }) 43 arguments.add(jarFile.absolutePath) 44 45 args = arguments 46 47 project.delete(outputDex) 48 outputDex.mkdirs() 49 50 super.exec() 51 } 52 } 53