diff --git a/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt b/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt index 96600efb05e..5787faea11b 100644 --- a/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt +++ b/buildSrc/src/main/kotlin/plugins/DexMethodCount.kt @@ -3,19 +3,22 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -import com.jakewharton.dex.* +import com.jakewharton.dex.DexMethod import com.jakewharton.dex.DexParser.Companion.toDexParser import org.gradle.api.DefaultTask import org.gradle.api.Project +import org.gradle.api.file.ProjectLayout import org.gradle.api.file.RegularFileProperty +import org.gradle.api.model.ObjectFactory import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property import org.gradle.api.tasks.* import org.gradle.jvm.tasks.Jar -import java.io.File +import org.gradle.kotlin.dsl.property +import javax.inject.Inject @CacheableTask -abstract class DexMethodCount : DefaultTask() { +abstract class DexMethodCount @Inject constructor(objectFactory: ObjectFactory, layout: ProjectLayout) : DefaultTask() { data class Counts( val total: Int, @@ -25,39 +28,33 @@ abstract class DexMethodCount : DefaultTask() { val byClass: Map ) - @Classpath - lateinit var jarFile: File + @get:InputFile + @get:Classpath + abstract val jarFile: RegularFileProperty @get:Optional @get:Input abstract val ownPackages: ListProperty - @Internal - var artifactName: String? = null - - private val projectName = project.name + private val projectName: String = project.name @get:Input - val artifactOrArchiveName: String - get() = artifactName ?: projectName + val artifactOrArchiveName: Property = objectFactory.property().convention(projectName) - fun from(jar: Jar) { - jarFile = jar.archiveFile.get().asFile - artifactName = jar.archiveBaseName.orNull - dependsOn(jar) + fun from(jar: TaskProvider) { + jarFile.set(jar.flatMap { it.archiveFile }) + artifactOrArchiveName.set(jar.flatMap { it.archiveBaseName.orElse(projectName) }) } @Internal // plain output properties are not supported, mark as internal to suppress warning from validatePlugins lateinit var counts: Counts @get:OutputFile - val detailOutputFile: File by lazy { - project.buildDir.resolve("$artifactOrArchiveName-method-count.txt") - } + val detailOutputFile: RegularFileProperty = objectFactory.fileProperty().value(artifactOrArchiveName.flatMap { layout.buildDirectory.file("$it-method-count.txt") }) @TaskAction fun invoke() { - val methods = jarFile.toDexParser().listMethods() + val methods = jarFile.get().asFile.toDexParser().listMethods() val counts = methods.getCounts().also { this.counts = it } outputDetails(counts) } @@ -83,7 +80,7 @@ abstract class DexMethodCount : DefaultTask() { } private fun outputDetails(counts: Counts) { - detailOutputFile.printWriter().use { writer -> + detailOutputFile.get().asFile.printWriter().use { writer -> writer.println("${counts.total.padRight()}\tTotal methods") ownPackages.orNull?.let { packages -> writer.println("${counts.totalOwnPackages?.padRight()}\tTotal methods from packages ${packages.joinToString { "$it.*" }}") @@ -150,9 +147,8 @@ abstract class DexMethodCountStats : DefaultTask() { fun Project.printStats(dexMethodCount: TaskProvider) { val dexMethodCountStats = tasks.register("dexMethodCountStats", DexMethodCountStats::class.java) { - dependsOn(dexMethodCount) - inputFile.set(dexMethodCount.flatMap { objects.fileProperty().apply { set(it.detailOutputFile) } }) - artifactOrArchiveName.set(dexMethodCount.map { it.artifactOrArchiveName }) + inputFile.set(dexMethodCount.flatMap { it.detailOutputFile }) + artifactOrArchiveName.set(dexMethodCount.flatMap { it.artifactOrArchiveName }) ownPackages.set(dexMethodCount.flatMap { it.ownPackages }) } diff --git a/libraries/reflect/build.gradle.kts b/libraries/reflect/build.gradle.kts index d98ebbc35b8..6473e62fdb6 100644 --- a/libraries/reflect/build.gradle.kts +++ b/libraries/reflect/build.gradle.kts @@ -244,15 +244,12 @@ val result by task { javadocJar() dexMethodCount { - dependsOn(result) - jarFile = result.get().outputs.files.single() + jarFile.fileProvider(result.map { it.outputs.files.singleFile }) ownPackages.set(listOf("kotlin.reflect")) } artifacts { listOf("archives", "runtimeElements").forEach { configurationName -> - add(configurationName, provider { result.get().outputs.files.singleFile }) { - builtBy(result) - } + add(configurationName, result.map { it.outputs.files.singleFile }) } } diff --git a/libraries/stdlib/jvm/build.gradle b/libraries/stdlib/jvm/build.gradle index da6c74abad5..92c1b653e6f 100644 --- a/libraries/stdlib/jvm/build.gradle +++ b/libraries/stdlib/jvm/build.gradle @@ -1,6 +1,8 @@ -description = 'Kotlin Standard Library for JVM' +plugins { + id("kotlin-platform-jvm") +} -apply plugin: 'kotlin-platform-jvm' +description = 'Kotlin Standard Library for JVM' archivesBaseName = 'kotlin-stdlib' @@ -93,7 +95,7 @@ dependencies { builtins project(':core:builtins') } -jar { +tasks.named("jar", Jar) { dependsOn(configurations.builtins) manifestAttributes(manifest, project, 'Main', true) from { @@ -104,7 +106,7 @@ jar { from sourceSets.java9.output } -sourcesJar { +tasks.named("sourcesJar", Jar) { from "${rootDir}/core/builtins/native" from(sourceSets.mainJdk7.allSource) { into 'jdk7' @@ -114,7 +116,7 @@ sourcesJar { } } -task distSourcesJar(type: Jar) { +tasks.create("distSourcesJar", Jar) { dependsOn(sourcesJar, configurations.commonSources) destinationDirectory = file("$buildDir/lib/dist") archiveClassifier.set('sources') @@ -136,7 +138,7 @@ artifacts { } DexMethodCountKt.dexMethodCount(project) { task -> - task.from(jar) + task.from(tasks.named("jar", Jar)) task.ownPackages = ['kotlin'] }