Browse Source

Minor refactoring on the Kotlin-dsl code style.
Use "register()" for lazy task creation.

Yao Wei Tjong 姚伟忠 6 years ago
parent
commit
34b1dece1a
2 changed files with 17 additions and 18 deletions
  1. 1 1
      android/launcher-app/build.gradle.kts
  2. 16 17
      android/urho3d-lib/build.gradle.kts

+ 1 - 1
android/launcher-app/build.gradle.kts

@@ -96,7 +96,7 @@ evaluationDependsOn(":android:urho3d-lib")
 
 
 afterEvaluate {
 afterEvaluate {
     tasks {
     tasks {
-        getByName("clean") {
+        named<Task>("clean") {
             doLast {
             doLast {
                 android.externalNativeBuild.cmake.path?.touch()
                 android.externalNativeBuild.cmake.path?.touch()
             }
             }

+ 16 - 17
android/urho3d-lib/build.gradle.kts

@@ -116,7 +116,7 @@ afterEvaluate {
     // When the buildDir is cleaned then we need a way to re-configure that part back
     // When the buildDir is cleaned then we need a way to re-configure that part back
     // It is achieved by ensuring that CMake configuration phase is rerun
     // It is achieved by ensuring that CMake configuration phase is rerun
     tasks {
     tasks {
-        getByName("clean") {
+        named<Task>("clean") {
             doLast {
             doLast {
                 android.externalNativeBuild.cmake.path?.touch()
                 android.externalNativeBuild.cmake.path?.touch()
             }
             }
@@ -127,13 +127,13 @@ afterEvaluate {
     android.buildTypes.forEach { buildType ->
     android.buildTypes.forEach { buildType ->
         val config = buildType.name.capitalize()
         val config = buildType.name.capitalize()
         tasks {
         tasks {
-            create<Zip>("zipBuildTree$config") {
+            register<Zip>("zipBuildTree$config") {
                 archiveClassifier.set(buildType.name)
                 archiveClassifier.set(buildType.name)
                 archiveExtension.set("aar")
                 archiveExtension.set("aar")
                 dependsOn("zipBuildTreeConfigurer$config", "bundle${config}Aar")
                 dependsOn("zipBuildTreeConfigurer$config", "bundle${config}Aar")
                 from(zipTree(getByName("bundle${config}Aar").outputs.files.first()))
                 from(zipTree(getByName("bundle${config}Aar").outputs.files.first()))
             }
             }
-            create("zipBuildTreeConfigurer$config") {
+            register<Task>("zipBuildTreeConfigurer$config") {
                 val externalNativeBuildDir = File(buildDir, "tree/$config")
                 val externalNativeBuildDir = File(buildDir, "tree/$config")
                 doLast {
                 doLast {
                     val zipTask = getByName<Zip>("zipBuildTree$config")
                     val zipTask = getByName<Zip>("zipBuildTree$config")
@@ -154,11 +154,11 @@ afterEvaluate {
 }
 }
 
 
 tasks {
 tasks {
-    create<Jar>("sourcesJar") {
+    register<Jar>("sourcesJar") {
         archiveClassifier.set("sources")
         archiveClassifier.set("sources")
         from(android.sourceSets.getByName("main").java.srcDirs)
         from(android.sourceSets.getByName("main").java.srcDirs)
     }
     }
-    create<Exec>("makeDoc") {
+    register<Exec>("makeDoc") {
         // Ignore the exit status on Windows host system because Doxygen may not return exit status correctly on Windows
         // Ignore the exit status on Windows host system because Doxygen may not return exit status correctly on Windows
         isIgnoreExitValue = OperatingSystem.current().isWindows
         isIgnoreExitValue = OperatingSystem.current().isWindows
         standardOutput = NullOutputStream.INSTANCE
         standardOutput = NullOutputStream.INSTANCE
@@ -166,19 +166,19 @@ tasks {
         dependsOn("makeDocConfigurer")
         dependsOn("makeDocConfigurer")
         mustRunAfter("zipBuildTreeRelease")
         mustRunAfter("zipBuildTreeRelease")
     }
     }
-    create<Zip>("documentationZip") {
+    register<Zip>("documentationZip") {
         archiveClassifier.set("documentation")
         archiveClassifier.set("documentation")
         dependsOn("makeDoc")
         dependsOn("makeDoc")
     }
     }
-    create("makeDocConfigurer") {
+    register<Task>("makeDocConfigurer") {
         doLast {
         doLast {
             val buildTree = File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/release/$docABI")
             val buildTree = File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/release/$docABI")
-            getByName<Exec>("makeDoc") {
+            named<Exec>("makeDoc") {
                 // This is a hack - expect the first line to contain the path to the embedded CMake executable
                 // This is a hack - expect the first line to contain the path to the embedded CMake executable
                 executable = File(buildTree, "cmake_build_command.txt").readLines().first().split(":").last().trim()
                 executable = File(buildTree, "cmake_build_command.txt").readLines().first().split(":").last().trim()
                 workingDir = buildTree
                 workingDir = buildTree
             }
             }
-            getByName<Zip>("documentationZip") {
+            named<Zip>("documentationZip") {
                 from(File(buildTree, "Docs/html")) {
                 from(File(buildTree, "Docs/html")) {
                     into("docs")
                     into("docs")
                 }
                 }
@@ -189,18 +189,18 @@ tasks {
 
 
 publishing {
 publishing {
     publications {
     publications {
-        create<MavenPublication>("mavenAndroid") {
+        register<MavenPublication>("mavenAndroid") {
             artifactId = "${project.name}-${project.libraryType}"
             artifactId = "${project.name}-${project.libraryType}"
             if (project.hasProperty("ANDROID_ABI")) {
             if (project.hasProperty("ANDROID_ABI")) {
                 artifactId = "$artifactId-${(project.property("ANDROID_ABI") as String).replace(',', '-')}"
                 artifactId = "$artifactId-${(project.property("ANDROID_ABI") as String).replace(',', '-')}"
             }
             }
             afterEvaluate {
             afterEvaluate {
                 android.buildTypes.forEach {
                 android.buildTypes.forEach {
-                    artifact(tasks.getByName("zipBuildTree${it.name.capitalize()}"))
+                    artifact(tasks["zipBuildTree${it.name.capitalize()}"])
                 }
                 }
             }
             }
-            artifact(tasks.getByName("sourcesJar"))
-            artifact(tasks.getByName("documentationZip"))
+            artifact(tasks["sourcesJar"])
+            artifact(tasks["documentationZip"])
             pom {
             pom {
                 @Suppress("UnstableApiUsage")
                 @Suppress("UnstableApiUsage")
                 inceptionYear.set("2008")
                 inceptionYear.set("2008")
@@ -242,7 +242,7 @@ bintray {
     publish = true
     publish = true
     override = true
     override = true
     setPublications("mavenAndroid")
     setPublications("mavenAndroid")
-    with(pkg) {
+    pkg.apply {
         repo = "maven"
         repo = "maven"
         name = project.name
         name = project.name
         setLicenses("MIT")
         setLicenses("MIT")
@@ -253,11 +253,10 @@ bintray {
         issueTrackerUrl = "https://github.com/urho3d/Urho3D/issues"
         issueTrackerUrl = "https://github.com/urho3d/Urho3D/issues"
         githubRepo = "urho3d/Urho3D"
         githubRepo = "urho3d/Urho3D"
         publicDownloadNumbers = true
         publicDownloadNumbers = true
-        desc = description
-        with(version) {
+        desc = project.description
+        version.apply {
             name = project.version.toString()
             name = project.version.toString()
             desc = "Continuous delivery from Travis-CI."
             desc = "Continuous delivery from Travis-CI."
-            vcsTag = ""
         }
         }
     }
     }
 }
 }