Browse Source

Initial work for custom Gradle plugin.
[skip appveyor] [ci only: Android]

Yao Wei Tjong 姚伟忠 7 years ago
parent
commit
a37ca0cb92

+ 10 - 2
android/launcher-app/build.gradle.kts

@@ -24,10 +24,9 @@ plugins {
     id("com.android.application")
     id("com.android.application")
     kotlin("android")
     kotlin("android")
     kotlin("android.extensions")
     kotlin("android.extensions")
+    urho3d("android")
 }
 }
 
 
-urhoAndroidModule()
-
 android {
 android {
     compileSdkVersion(27)
     compileSdkVersion(27)
     defaultConfig {
     defaultConfig {
@@ -82,6 +81,15 @@ android {
     }
     }
 }
 }
 
 
+dependencies {
+    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
+    implementation(project(":android:urho3d-lib"))
+    implementation(kotlin("stdlib-jdk8", kotlinVersion))
+    testImplementation("junit:junit:$junitVersion")
+    androidTestImplementation("com.android.support.test:runner:$testRunnerVersion")
+    androidTestImplementation("com.android.support.test.espresso:espresso-core:$testEspressoVersion")
+}
+
 // Ensure IDE "gradle sync" evaluate the urho3d-lib module first
 // Ensure IDE "gradle sync" evaluate the urho3d-lib module first
 evaluationDependsOn(":android:urho3d-lib")
 evaluationDependsOn(":android:urho3d-lib")
 
 

+ 8 - 1
android/urho3d-lib/build.gradle.kts

@@ -98,7 +98,10 @@ android {
 
 
 dependencies {
 dependencies {
     implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
     implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
-    kotlinAndroidDependencies()
+    implementation(kotlin("stdlib-jdk8", kotlinVersion))
+    testImplementation("junit:junit:$junitVersion")
+    androidTestImplementation("com.android.support.test:runner:$testRunnerVersion")
+    androidTestImplementation("com.android.support.test.espresso:espresso-core:$testEspressoVersion")
 }
 }
 
 
 lateinit var docABI: String
 lateinit var docABI: String
@@ -182,6 +185,7 @@ tasks {
 publishing {
 publishing {
     (publications) {
     (publications) {
         create<MavenPublication>("mavenAndroid") {
         create<MavenPublication>("mavenAndroid") {
+            artifactId = "${project.name}-${project.libraryType}"
             afterEvaluate {
             afterEvaluate {
                 android.buildTypes.forEach {
                 android.buildTypes.forEach {
                     artifact(tasks.getByName("zipBuildTree${it.name.capitalize()}"))
                     artifact(tasks.getByName("zipBuildTree${it.name.capitalize()}"))
@@ -194,3 +198,6 @@ publishing {
 }
 }
 
 
 fun cmakeStagingDir() = android.externalNativeBuild.cmake.buildStagingDirectory ?: project.file(".externalNativeBuild")
 fun cmakeStagingDir() = android.externalNativeBuild.cmake.buildStagingDirectory ?: project.file(".externalNativeBuild")
+
+val Project.libraryType: String
+    get() = if (hasProperty("URHO3D_LIB_TYPE")) property("URHO3D_LIB_TYPE") as String else "STATIC"

+ 7 - 24
buildSrc/src/main/kotlin/UrhoCommon.kt

@@ -20,11 +20,8 @@
 // THE SOFTWARE.
 // THE SOFTWARE.
 //
 //
 
 
-import org.gradle.api.Project
-import org.gradle.kotlin.dsl.DependencyHandlerScope
-import org.gradle.kotlin.dsl.dependencies
-import org.gradle.kotlin.dsl.kotlin
-import org.gradle.kotlin.dsl.project
+import org.gradle.plugin.use.PluginDependenciesSpec
+import org.gradle.plugin.use.PluginDependencySpec
 import java.io.File
 import java.io.File
 
 
 const val androidToolsVersion = "3.2.0-beta04"
 const val androidToolsVersion = "3.2.0-beta04"
@@ -34,27 +31,13 @@ const val testRunnerVersion = "1.0.2"
 const val testEspressoVersion = "3.0.2"
 const val testEspressoVersion = "3.0.2"
 
 
 /**
 /**
- * Prepare the module as Android Application with Urho3D AAR dependency.
+ * Apply Urho3D custom plugin for the given platform.
+ *
+ * Current supported platforms: android.
  */
  */
 @Suppress("unused")
 @Suppress("unused")
-fun Project.urhoAndroidModule() {
-    dependencies {
-        "implementation"(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
-        "implementation"(project(":android:urho3d-lib"))
-        kotlinAndroidDependencies()
-    }
-}
-
-/**
- * Add default dependencies for Android/Kotlin module.
- */
-@Suppress("unused")
-fun DependencyHandlerScope.kotlinAndroidDependencies() {
-    "implementation"(kotlin("stdlib-jdk8", kotlinVersion))
-    "testImplementation"("junit:junit:$junitVersion")
-    "androidTestImplementation"("com.android.support.test:runner:$testRunnerVersion")
-    "androidTestImplementation"("com.android.support.test.espresso:espresso-core:$testEspressoVersion")
-}
+fun PluginDependenciesSpec.urho3d(platform: String): PluginDependencySpec =
+        id("com.github.urho3d.$platform")
 
 
 /**
 /**
  * Naive implementation of "touch" command.
  * Naive implementation of "touch" command.

+ 29 - 0
buildSrc/src/main/kotlin/com/github/urho3d/gradle/BaseExtension.kt

@@ -0,0 +1,29 @@
+//
+// Copyright (c) 2008-2018 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+package com.github.urho3d.gradle
+
+open class BaseExtension {
+
+    var libraryType = "STATIC"
+
+}

+ 28 - 0
buildSrc/src/main/kotlin/com/github/urho3d/gradle/BasePlugin.kt

@@ -0,0 +1,28 @@
+//
+// Copyright (c) 2008-2018 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+package com.github.urho3d.gradle
+
+import org.gradle.api.Plugin
+import org.gradle.api.Project
+
+abstract class BasePlugin : Plugin<Project>

+ 40 - 0
buildSrc/src/main/kotlin/com/github/urho3d/gradle/android/AndroidPlugin.kt

@@ -0,0 +1,40 @@
+//
+// Copyright (c) 2008-2018 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+package com.github.urho3d.gradle.android
+
+import com.github.urho3d.gradle.BasePlugin
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.invoke
+
+open class AndroidPlugin : BasePlugin() {
+
+    override fun apply(target: Project) {
+        target.run {
+            val extension = extensions.create("urho3d", AndroidPluginExtension::class.java)
+            tasks {
+                // TODO: declare custom tasks here
+            }
+        }
+    }
+
+}

+ 27 - 0
buildSrc/src/main/kotlin/com/github/urho3d/gradle/android/AndroidPluginExtension.kt

@@ -0,0 +1,27 @@
+//
+// Copyright (c) 2008-2018 the Urho3D project.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+package com.github.urho3d.gradle.android
+
+import com.github.urho3d.gradle.BaseExtension
+
+open class AndroidPluginExtension : BaseExtension()

+ 1 - 0
buildSrc/src/main/resources/META-INF/gradle-plugins/com.github.urho3d.android.properties

@@ -0,0 +1 @@
+implementation-class=com.github.urho3d.gradle.android.AndroidPlugin