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")
|
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()
|
val dependency = it.toDependency()
|
||||||
dependencies.add(cfg.name, dependency)
|
dependencies.add(cfg.name, dependency)
|
||||||
|
|
||||||
val t = task<Copy>("unzip_$id") {
|
val t = task("unzip_$id") {
|
||||||
afterEvaluate {
|
dependsOn(cfg)
|
||||||
from(zipTree(cfg.singleFile))
|
inputs.files(cfg)
|
||||||
}
|
val targetDir = file("$sdkDestDir/${it.dest}")
|
||||||
into(file("$sdkDestDir/${it.dest}"))
|
val targetFlagFile = File(targetDir, "$id.prepared")
|
||||||
}
|
outputs.files(targetFlagFile)
|
||||||
if (it.dirLevelsToSkit > 0) {
|
outputs.upToDateWhen { targetFlagFile.exists() } // TODO: consider more precise check, e.g. hash-based
|
||||||
t.apply {
|
doFirst {
|
||||||
eachFile {
|
project.copy {
|
||||||
path = path.split("/").drop(it.dirLevelsToSkit).joinToString("/")
|
from(zipTree(cfg.singleFile))
|
||||||
|
if (it.dirLevelsToSkit > 0) {
|
||||||
|
eachFile {
|
||||||
|
path = path.split("/").drop(it.dirLevelsToSkit).joinToString("/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
into(targetDir)
|
||||||
}
|
}
|
||||||
|
targetFlagFile.writeText("prepared")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prepareSdk.dependsOn(t)
|
prepareSdk.dependsOn(t)
|
||||||
@@ -80,20 +87,32 @@ val clean by task<Delete> {
|
|||||||
delete(buildDir)
|
delete(buildDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
val extractAndroidJar by task<Copy> {
|
val extractAndroidJar by tasks.creating {
|
||||||
configurations.add(androidJar)
|
dependsOn(androidPlatform)
|
||||||
afterEvaluate {
|
inputs.files(androidPlatform)
|
||||||
from(zipTree(androidPlatform.singleFile).matching { include("**/android.jar") }.files.first())
|
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> {
|
val extractDxJar by tasks.creating {
|
||||||
configurations.add(dxJar)
|
dependsOn(buildTools)
|
||||||
afterEvaluate {
|
inputs.files(buildTools)
|
||||||
from(zipTree(buildTools.singleFile).matching { include("**/dx.jar") }.files.first())
|
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")) {
|
artifacts.add(androidSdk.name, file("$sdkDestDir")) {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ configureIntellijPlugin {
|
|||||||
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val androidSdk by configurations.creating
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
compileOnly(project(":kotlin-reflect-api"))
|
||||||
compile(project(":compiler:util"))
|
compile(project(":compiler:util"))
|
||||||
@@ -36,6 +38,7 @@ dependencies {
|
|||||||
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
||||||
testRuntime(project(":noarg-ide-plugin"))
|
testRuntime(project(":noarg-ide-plugin"))
|
||||||
testRuntime(project(":allopen-ide-plugin"))
|
testRuntime(project(":allopen-ide-plugin"))
|
||||||
|
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
@@ -65,8 +68,11 @@ tasks.withType<KotlinCompile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
projectTest {
|
projectTest {
|
||||||
|
dependsOn(androidSdk)
|
||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
systemProperty("android.sdk", androidSdkPath())
|
doFirst {
|
||||||
|
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testsJar {}
|
testsJar {}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ configureIntellijPlugin {
|
|||||||
setPlugins("android", "coverage", "gradle", "Groovy", "junit", "maven", "properties", "testng")
|
setPlugins("android", "coverage", "gradle", "Groovy", "junit", "maven", "properties", "testng")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val androidSdk by configurations.creating
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
compileOnly(project(":idea"))
|
compileOnly(project(":idea"))
|
||||||
@@ -28,6 +30,7 @@ dependencies {
|
|||||||
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
testRuntime(project(":sam-with-receiver-ide-plugin"))
|
||||||
testRuntime(project(":allopen-ide-plugin"))
|
testRuntime(project(":allopen-ide-plugin"))
|
||||||
testRuntime(project(":noarg-ide-plugin"))
|
testRuntime(project(":noarg-ide-plugin"))
|
||||||
|
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
@@ -62,7 +65,10 @@ testsJar()
|
|||||||
|
|
||||||
projectTest {
|
projectTest {
|
||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
systemProperty("android.sdk", androidSdkPath())
|
dependsOn(androidSdk)
|
||||||
|
doFirst {
|
||||||
|
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
configureInstrumentation()
|
configureInstrumentation()
|
||||||
|
|||||||
@@ -87,7 +87,9 @@ tasks.withType(Test) {
|
|||||||
if (mavenLocalRepo != null) {
|
if (mavenLocalRepo != null) {
|
||||||
systemProperty("maven.repo.local", mavenLocalRepo)
|
systemProperty("maven.repo.local", mavenLocalRepo)
|
||||||
}
|
}
|
||||||
systemProperty("android.sdk", project.configurations["androidSdk"].singleFile.getCanonicalPath())
|
doFirst {
|
||||||
|
systemProperty("android.sdk", project.configurations["androidSdk"].singleFile.getCanonicalPath())
|
||||||
|
}
|
||||||
|
|
||||||
testLogging {
|
testLogging {
|
||||||
// set options for log level LIFECYCLE
|
// set options for log level LIFECYCLE
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ configureIntellijPlugin {
|
|||||||
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
"java-decompiler", "java-i18n", "junit", "maven", "properties", "testng")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val androidSdk by configurations.creating
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile(project(":compiler:util"))
|
compile(project(":compiler:util"))
|
||||||
compile(project(":compiler:light-classes"))
|
compile(project(":compiler:light-classes"))
|
||||||
@@ -36,6 +38,7 @@ dependencies {
|
|||||||
testRuntime(project(":noarg-ide-plugin"))
|
testRuntime(project(":noarg-ide-plugin"))
|
||||||
testRuntime(project(":allopen-ide-plugin"))
|
testRuntime(project(":allopen-ide-plugin"))
|
||||||
testRuntime(project(":plugins:lint"))
|
testRuntime(project(":plugins:lint"))
|
||||||
|
androidSdk(project(":custom-dependencies:android-sdk", configuration = "androidSdk"))
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
@@ -61,8 +64,11 @@ testsJar {}
|
|||||||
|
|
||||||
projectTest {
|
projectTest {
|
||||||
dependsOn(":kotlin-android-extensions-runtime:dist")
|
dependsOn(":kotlin-android-extensions-runtime:dist")
|
||||||
|
dependsOn(androidSdk)
|
||||||
workingDir = rootDir
|
workingDir = rootDir
|
||||||
systemProperty("android.sdk", androidSdkPath())
|
doFirst {
|
||||||
|
systemProperty("android.sdk", androidSdk.singleFile.canonicalPath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runtimeJar()
|
runtimeJar()
|
||||||
|
|||||||
Reference in New Issue
Block a user