Rewrite android sdk dependencies to avoid config-time tasks execution
This commit is contained in:
committed by
Vyacheslav Gerasimov
parent
febab82c7e
commit
46be5e25be
@@ -100,18 +100,3 @@ fun firstFromJavaHomeThatExists(vararg paths: String): File? =
|
||||
|
||||
fun toolsJar(): File? = firstFromJavaHomeThatExists("../lib/tools.jar", "../Classes/tools.jar")
|
||||
|
||||
private fun Task.addConfigurationAndProjectDependency(name: String, sourceProject: String, sourceConfiguration: String, sourceTask: String): Configuration {
|
||||
dependsOn("$sourceProject:$sourceTask")
|
||||
return project.configurations.findByName(name) // assuming that dependency is already added too
|
||||
?: project.configurations.create(name).also {
|
||||
DependencyHandlerScope(project.dependencies).let { dh -> dh.add(name, dh.project(sourceProject, configuration = sourceConfiguration)) }
|
||||
}
|
||||
}
|
||||
|
||||
fun Task.androidSdkPath(): String =
|
||||
addConfigurationAndProjectDependency("androidSdk", ":custom-dependencies:android-sdk", "androidSdk", "prepareSdk")
|
||||
.singleFile.canonicalPath
|
||||
|
||||
fun Task.androidJarPath(): String =
|
||||
addConfigurationAndProjectDependency("androidJar", ":custom-dependencies:android-sdk", "androidJar", "extractAndroidJar")
|
||||
.singleFile.canonicalPath
|
||||
|
||||
@@ -56,17 +56,24 @@ sdkLocMaps.forEach {
|
||||
val dependency = it.toDependency()
|
||||
dependencies.add(cfg.name, dependency)
|
||||
|
||||
val t = task<Copy>("unzip_$id") {
|
||||
afterEvaluate {
|
||||
from(zipTree(cfg.singleFile))
|
||||
}
|
||||
into(file("$sdkDestDir/${it.dest}"))
|
||||
}
|
||||
if (it.dirLevelsToSkit > 0) {
|
||||
t.apply {
|
||||
eachFile {
|
||||
path = path.split("/").drop(it.dirLevelsToSkit).joinToString("/")
|
||||
val t = task("unzip_$id") {
|
||||
dependsOn(cfg)
|
||||
inputs.files(cfg)
|
||||
val targetDir = file("$sdkDestDir/${it.dest}")
|
||||
val targetFlagFile = File(targetDir, "$id.prepared")
|
||||
outputs.files(targetFlagFile)
|
||||
outputs.upToDateWhen { targetFlagFile.exists() } // TODO: consider more precise check, e.g. hash-based
|
||||
doFirst {
|
||||
project.copy {
|
||||
from(zipTree(cfg.singleFile))
|
||||
if (it.dirLevelsToSkit > 0) {
|
||||
eachFile {
|
||||
path = path.split("/").drop(it.dirLevelsToSkit).joinToString("/")
|
||||
}
|
||||
}
|
||||
into(targetDir)
|
||||
}
|
||||
targetFlagFile.writeText("prepared")
|
||||
}
|
||||
}
|
||||
prepareSdk.dependsOn(t)
|
||||
@@ -80,20 +87,32 @@ val clean by task<Delete> {
|
||||
delete(buildDir)
|
||||
}
|
||||
|
||||
val extractAndroidJar by task<Copy> {
|
||||
configurations.add(androidJar)
|
||||
afterEvaluate {
|
||||
from(zipTree(androidPlatform.singleFile).matching { include("**/android.jar") }.files.first())
|
||||
val extractAndroidJar by tasks.creating {
|
||||
dependsOn(androidPlatform)
|
||||
inputs.files(androidPlatform)
|
||||
val targetFile = File(libsDestDir, "android.jar")
|
||||
outputs.files(targetFile)
|
||||
outputs.upToDateWhen { targetFile.exists() } // TODO: consider more precise check, e.g. hash-based
|
||||
doFirst {
|
||||
project.copy {
|
||||
from(zipTree(androidPlatform.singleFile).matching { include("**/android.jar") }.files.first())
|
||||
into(libsDestDir)
|
||||
}
|
||||
}
|
||||
into(libsDestDir)
|
||||
}
|
||||
|
||||
val extractDxJar by task<Copy> {
|
||||
configurations.add(dxJar)
|
||||
afterEvaluate {
|
||||
from(zipTree(buildTools.singleFile).matching { include("**/dx.jar") }.files.first())
|
||||
val extractDxJar by tasks.creating {
|
||||
dependsOn(buildTools)
|
||||
inputs.files(buildTools)
|
||||
val targetFile = File(libsDestDir, "dx.jar")
|
||||
outputs.files(targetFile)
|
||||
outputs.upToDateWhen { targetFile.exists() } // TODO: consider more precise check, e.g. hash-based
|
||||
doFirst {
|
||||
project.copy {
|
||||
from(zipTree(buildTools.singleFile).matching { include("**/dx.jar") }.files.first())
|
||||
into(libsDestDir)
|
||||
}
|
||||
}
|
||||
into(libsDestDir)
|
||||
}
|
||||
|
||||
artifacts.add(androidSdk.name, file("$sdkDestDir")) {
|
||||
|
||||
@@ -7,6 +7,8 @@ configureIntellijPlugin {
|
||||
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
||||
}
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
compileOnly(project(":kotlin-reflect-api"))
|
||||
compile(project(":compiler:util"))
|
||||
@@ -36,6 +38,7 @@ dependencies {
|
||||
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
||||
testRuntime(project(":noarg-ide-plugin"))
|
||||
testRuntime(project(":allopen-ide-plugin"))
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
@@ -65,8 +68,11 @@ tasks.withType<KotlinCompile> {
|
||||
}
|
||||
|
||||
projectTest {
|
||||
dependsOn(androidSdk)
|
||||
workingDir = rootDir
|
||||
systemProperty("android.sdk", androidSdkPath())
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
testsJar {}
|
||||
|
||||
@@ -4,6 +4,8 @@ configureIntellijPlugin {
|
||||
setPlugins("android", "coverage", "gradle", "Groovy", "junit", "maven", "properties", "testng")
|
||||
}
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
|
||||
compileOnly(project(":idea"))
|
||||
@@ -28,6 +30,7 @@ dependencies {
|
||||
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
||||
testRuntime(project(":allopen-ide-plugin"))
|
||||
testRuntime(project(":noarg-ide-plugin"))
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
@@ -62,7 +65,10 @@ testsJar()
|
||||
|
||||
projectTest {
|
||||
workingDir = rootDir
|
||||
systemProperty("android.sdk", androidSdkPath())
|
||||
dependsOn(androidSdk)
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
configureInstrumentation()
|
||||
|
||||
@@ -87,7 +87,9 @@ tasks.withType(Test) {
|
||||
if (mavenLocalRepo != null) {
|
||||
systemProperty("maven.repo.local", mavenLocalRepo)
|
||||
}
|
||||
systemProperty("android.sdk", project.configurations["androidSdk"].singleFile.getCanonicalPath())
|
||||
doFirst {
|
||||
systemProperty("android.sdk", project.configurations["androidSdk"].singleFile.getCanonicalPath())
|
||||
}
|
||||
|
||||
testLogging {
|
||||
// set options for log level LIFECYCLE
|
||||
|
||||
@@ -10,6 +10,8 @@ configureIntellijPlugin {
|
||||
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
||||
}
|
||||
|
||||
val androidSdk by configurations.creating
|
||||
|
||||
dependencies {
|
||||
compile(project(":compiler:util"))
|
||||
compile(project(":compiler:light-classes"))
|
||||
@@ -36,6 +38,7 @@ dependencies {
|
||||
testRuntime(project(":noarg-ide-plugin"))
|
||||
testRuntime(project(":allopen-ide-plugin"))
|
||||
testRuntime(project(":plugins:lint"))
|
||||
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
@@ -61,8 +64,11 @@ testsJar {}
|
||||
|
||||
projectTest {
|
||||
dependsOn(":kotlin-android-extensions-runtime:dist")
|
||||
dependsOn(androidSdk)
|
||||
workingDir = rootDir
|
||||
systemProperty("android.sdk", androidSdkPath())
|
||||
doFirst {
|
||||
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||
}
|
||||
}
|
||||
|
||||
runtimeJar()
|
||||
|
||||
Reference in New Issue
Block a user