From 47507ad694cff17ac02c5df56e07f4dcad30c4ec Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 6 Dec 2017 17:47:28 +0100 Subject: [PATCH] Switch all usages of dx.jar to the new mechanism, cleanup and refactoring --- buildSrc/build.gradle.kts | 2 +- .../{dx => android-dx}/build.gradle.kts | 13 ++++++------- buildSrc/settings.gradle | 2 +- buildSrc/src/main/kotlin/AndroidSdkDependencies.kt | 11 +++++++++++ compiler/build.gradle.kts | 6 +++++- compiler/tests-common/build.gradle.kts | 6 ++---- custom-dependencies/android-sdk/build.gradle.kts | 1 - idea/idea-android/build.gradle.kts | 10 +++++----- plugins/lint/build.gradle.kts | 4 ++++ 9 files changed, 35 insertions(+), 20 deletions(-) rename buildSrc/prepare-deps/{dx => android-dx}/build.gradle.kts (83%) create mode 100644 buildSrc/src/main/kotlin/AndroidSdkDependencies.kt diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 8316317ef9c..cf1cb30f333 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -63,4 +63,4 @@ samWithReceiver { fun Project.`samWithReceiver`(configure: org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension.() -> Unit): Unit = extensions.configure("samWithReceiver", configure) -tasks["build"].dependsOn(":prepare-deps:dx:build") +tasks["build"].dependsOn(":prepare-deps:android-dx:build") diff --git a/buildSrc/prepare-deps/dx/build.gradle.kts b/buildSrc/prepare-deps/android-dx/build.gradle.kts similarity index 83% rename from buildSrc/prepare-deps/dx/build.gradle.kts rename to buildSrc/prepare-deps/android-dx/build.gradle.kts index d989c1ed56b..4ba355a3d0a 100644 --- a/buildSrc/prepare-deps/dx/build.gradle.kts +++ b/buildSrc/prepare-deps/android-dx/build.gradle.kts @@ -24,6 +24,8 @@ repositories { } } +val dxRepoDir = File(buildDir, "libs") + val buildToolsZip by configurations.creating val dxSourcesTar by configurations.creating @@ -35,14 +37,12 @@ dependencies { val unzipDxJar by tasks.creating { dependsOn(buildToolsZip) inputs.files(buildToolsZip) - val targetFile = File(buildDir, "dx.jar") - outputs.files(targetFile) - outputs.upToDateWhen { targetFile.exists() } // TODO: consider more precise check, e.g. hash-based + outputs.files(File(dxRepoDir, "dx.jar")) doFirst { project.copy { from(zipTree(buildToolsZip.singleFile).files) include("**/dx.jar") - into(buildDir) + into(dxRepoDir) } } } @@ -52,8 +52,7 @@ val dxSourcesTargetDir = File(buildDir, "dx_src") val untarDxSources by tasks.creating { dependsOn(dxSourcesTar) inputs.files(dxSourcesTar) - outputs.files(dxSourcesTargetDir) - outputs.upToDateWhen { dxSourcesTargetDir.isDirectory } // TODO: consider more precise check, e.g. hash-based + outputs.dir(dxSourcesTargetDir) doFirst { project.copy { from(tarTree(dxSourcesTar.singleFile)) @@ -67,7 +66,7 @@ val untarDxSources by tasks.creating { val prepareDxSourcesJar by tasks.creating(Jar::class) { dependsOn(untarDxSources) from("$dxSourcesTargetDir/src") - destinationDir = buildDir + destinationDir = dxRepoDir baseName = "dx" classifier = "sources" } diff --git a/buildSrc/settings.gradle b/buildSrc/settings.gradle index 1675a57a972..8b34b71f2e5 100644 --- a/buildSrc/settings.gradle +++ b/buildSrc/settings.gradle @@ -1,3 +1,3 @@ -include "prepare-deps:dx", +include "prepare-deps:android-dx", "prepare-deps:intellij-sdk" diff --git a/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt b/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt new file mode 100644 index 00000000000..1629aeac60c --- /dev/null +++ b/buildSrc/src/main/kotlin/AndroidSdkDependencies.kt @@ -0,0 +1,11 @@ +@file:Suppress("unused") // usages in build scripts are not tracked properly + +import org.gradle.api.Project +import org.gradle.api.artifacts.dsl.RepositoryHandler +import org.gradle.api.artifacts.repositories.IvyArtifactRepository + +fun RepositoryHandler.androidDxJarRepo(project: Project): IvyArtifactRepository = ivy { + artifactPattern("${project.rootDir.absoluteFile.toURI().toURL()}/buildSrc/prepare-deps/android-dx/build/libs/[artifact](-[classifier]).jar") +} + +fun androidDxJar() = "my-custom-deps:dx:0" diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index 2ae6793dc63..f90842d6ced 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -6,6 +6,10 @@ apply { plugin("kotlin") } jvmTarget = "1.6" +repositories { + androidDxJarRepo(project) +} + configureIntellijPlugin { setExtraDependencies("intellij-core") } @@ -62,7 +66,7 @@ dependencies { testRuntime(projectDist(":kotlin-reflect")) testRuntime(projectDist(":kotlin-daemon-client")) - testRuntime(project(":custom-dependencies:android-sdk", configuration = "dxJar")) + testRuntime(androidDxJar()) testRuntime(files(toolsJar())) testJvm6ServerRuntime(projectTests(":compiler:tests-common-jvm6")) diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index deba642dc5c..35d7fc1acbd 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -6,9 +6,7 @@ configureIntellijPlugin { } repositories { - ivy { - artifactPattern("${rootDir.absoluteFile.toURI().toURL()}/buildSrc/prepare-deps/dx/build/[artifact](-[classifier]).jar") - } + androidDxJarRepo(project) } dependencies { @@ -35,7 +33,7 @@ dependencies { testCompile(projectTests(":compiler:tests-common-jvm6")) testCompileOnly(project(":kotlin-reflect-api")) testCompile(commonDep("junit:junit")) - testCompile("my-custom-deps:dx:0") + testCompile(androidDxJar()) } afterEvaluate { diff --git a/custom-dependencies/android-sdk/build.gradle.kts b/custom-dependencies/android-sdk/build.gradle.kts index 91e0e568850..61bd124be7a 100644 --- a/custom-dependencies/android-sdk/build.gradle.kts +++ b/custom-dependencies/android-sdk/build.gradle.kts @@ -16,7 +16,6 @@ repositories { val androidSdk by configurations.creating val androidJar by configurations.creating -val dxJar by configurations.creating val androidPlatform by configurations.creating val dxSources by configurations.creating val buildTools by configurations.creating diff --git a/idea/idea-android/build.gradle.kts b/idea/idea-android/build.gradle.kts index ecea7798927..4b3d1535007 100644 --- a/idea/idea-android/build.gradle.kts +++ b/idea/idea-android/build.gradle.kts @@ -2,6 +2,10 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile apply { plugin("kotlin") } +repositories { + androidDxJarRepo(project) +} + configureIntellijPlugin { setPlugins("android", "copyright", "coverage", "gradle", "Groovy", "IntelliLang", "java-decompiler", "java-i18n", "junit", "maven", "properties", "testng") @@ -21,7 +25,7 @@ dependencies { compile(project(":idea:ide-common")) compile(project(":idea:idea-gradle")) - compile(project(":custom-dependencies:android-sdk", configuration = "dxJar")) + compile(androidDxJar()) testCompile(projectDist(":kotlin-test:kotlin-test-jvm")) testCompile(project(":idea:idea-test-framework")) { isTransitive = false } @@ -63,10 +67,6 @@ sourceSets { "test" { projectDefault() } } -tasks.withType { - dependsOn(":custom-dependencies:android-sdk:extractDxJar") -} - projectTest { dependsOn(androidSdk) workingDir = rootDir diff --git a/plugins/lint/build.gradle.kts b/plugins/lint/build.gradle.kts index 9975fba0ab4..e946d11e686 100644 --- a/plugins/lint/build.gradle.kts +++ b/plugins/lint/build.gradle.kts @@ -4,6 +4,10 @@ apply { plugin("java") } +repositories { + androidDxJarRepo(project) +} + configureIntellijPlugin { setExtraDependencies("intellij-core") setPlugins("android")