diff --git a/sample/app/src/main/java/com/grab/android/sample/MainActivity.kt b/sample/app/src/main/java/com/grab/android/sample/MainActivity.kt index 7ddc79e..0fd013b 100644 --- a/sample/app/src/main/java/com/grab/android/sample/MainActivity.kt +++ b/sample/app/src/main/java/com/grab/android/sample/MainActivity.kt @@ -10,6 +10,7 @@ import androidx.navigation.ui.setupActionBarWithNavController import android.view.Menu import android.view.MenuItem import com.grab.android.sample.databinding.ActivityMainBinding +import com.grab.sample.dummy.KMPDummyClass1 import com.grab.sample.dummy.KDummyClass1 class MainActivity : AppCompatActivity() { @@ -35,6 +36,7 @@ class MainActivity : AppCompatActivity() { } KDummyClass1().method1() + KMPDummyClass1().method1() } override fun onCreateOptionsMenu(menu: Menu): Boolean { diff --git a/sample/build-logic/build.gradle b/sample/build-logic/build.gradle index d3d1b1a..482c0dc 100644 --- a/sample/build-logic/build.gradle +++ b/sample/build-logic/build.gradle @@ -40,24 +40,26 @@ dependencies { compileOnly libs.android.gradle.plugin } + gradlePlugin { plugins { androidAppConfigPlugin { id = 'com.sample.android.application' - implementationClass = 'com.grab.sample.buildplugin.AndroidAppConfigPlugin' + implementationClass = 'com.grab.sample.android.AndroidAppConfigPlugin' } androidLibConfigPlugin { id = 'com.sample.android.library' - implementationClass = 'com.grab.sample.buildplugin.AndroidLibraryConfigPlugin' + implementationClass = 'com.grab.sample.android.AndroidLibraryConfigPlugin' + } + + kotlinKmpConfigPlugin { + id = 'com.sample.kotlin.kmp' + implementationClass = 'com.grab.sample.jvm.KmpConfigPlugin' } kotlinLibConfigPlugin { id = 'com.sample.kotlin.library' - implementationClass = 'com.grab.sample.buildplugin.KotlinLibraryConfigPlugin' - } - kotlinMultiplatformLibConfigPlugin { - id = 'com.sample.kotlin.multiplatform.library' - implementationClass = 'com.grab.sample.buildplugin.KotlinMultiplatformLibraryConfigPlugin' + implementationClass = 'com.grab.sample.jvm.KotlinLibraryConfigPlugin' } } } \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/Constants.kt b/sample/build-logic/src/main/java/com/grab/sample/Constants.kt new file mode 100644 index 0000000..a925fc0 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/Constants.kt @@ -0,0 +1,40 @@ +/* + * MIT License + * + * Copyright (c) 2024. Grabtaxi Holdings Pte Ltd (GRAB), All rights reserved. + * + * + * 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.grab.sample + +import org.gradle.api.JavaVersion + +object BuildConfig { + const val COMPILE_SDK = 34 + const val JVM_TARGET = "17" + val JAVA_VERSION = JavaVersion.VERSION_17 + const val MIN_SDK = 21 + const val TARGET_SDK = 33 + const val APPLICATION_ID = "com.grab.android.sample" + const val TEST_INSTRUMENTATION_RUNNER = "androidx.test.runner.AndroidJUnitRunner" +} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/android/AndroidAppConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/android/AndroidAppConfigPlugin.kt new file mode 100644 index 0000000..33c0d59 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/android/AndroidAppConfigPlugin.kt @@ -0,0 +1,56 @@ +/* + * MIT License + * + * Copyright (c) 2024. Grabtaxi Holdings Pte Ltd (GRAB), All rights reserved. + * + * + * 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.grab.sample.android + +import com.android.build.api.dsl.ApplicationExtension +import com.grab.sample.BuildConfig +import com.grab.sample.gradle.ConfigurablePlugin +import com.grab.sample.jvm.kotlinCommon +import org.gradle.kotlin.dsl.configure + +class AndroidAppConfigPlugin : ConfigurablePlugin({ + plugins.apply("com.android.application") + plugins.apply("org.jetbrains.kotlin.android") + + extensions.configure { + compileSdk = BuildConfig.COMPILE_SDK + + defaultConfig { + applicationId = BuildConfig.APPLICATION_ID + minSdk = BuildConfig.MIN_SDK + targetSdk = BuildConfig.TARGET_SDK + } + + compileOptions { + sourceCompatibility = BuildConfig.JAVA_VERSION + targetCompatibility = BuildConfig.JAVA_VERSION + } + } + + kotlinCommon() +}) \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/android/AndroidLibraryConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/android/AndroidLibraryConfigPlugin.kt new file mode 100644 index 0000000..992ed88 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/android/AndroidLibraryConfigPlugin.kt @@ -0,0 +1,56 @@ +/* + * MIT License + * + * Copyright (c) 2024. Grabtaxi Holdings Pte Ltd (GRAB), All rights reserved. + * + * + * 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.grab.sample.android + + +import com.android.build.gradle.LibraryExtension +import com.grab.sample.BuildConfig +import com.grab.sample.gradle.ConfigurablePlugin +import com.grab.sample.jvm.kotlinCommon +import org.gradle.kotlin.dsl.configure + +class AndroidLibraryConfigPlugin : ConfigurablePlugin({ + plugins.apply("com.android.library") + plugins.apply("kotlin-android") + + extensions.configure { + compileSdk = BuildConfig.COMPILE_SDK + + defaultConfig { + minSdk = BuildConfig.MIN_SDK + testInstrumentationRunner = BuildConfig.TEST_INSTRUMENTATION_RUNNER + consumerProguardFiles("consumer-rules.pro") + } + + compileOptions { + sourceCompatibility = BuildConfig.JAVA_VERSION + targetCompatibility = BuildConfig.JAVA_VERSION + } + } + + kotlinCommon() +}) \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidAppConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidAppConfigPlugin.kt deleted file mode 100644 index e08b779..0000000 --- a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidAppConfigPlugin.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.grab.sample.buildplugin - -import com.android.build.api.dsl.ApplicationExtension -import org.gradle.api.JavaVersion -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.configure -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -internal const val COMPILE_SDK = 34 -internal const val JVM_TARGET = "17" -internal val JAVA_VERSION = JavaVersion.VERSION_17 -internal const val MIN_SDK = 21 -internal const val TARGET_SDK = 33 - -class AndroidAppConfigPlugin : Plugin { - override fun apply(project: Project) { - with(project) { - plugins.apply("com.android.application") - plugins.apply("org.jetbrains.kotlin.android") - - extensions.configure { - compileSdk = COMPILE_SDK - - defaultConfig { - applicationId = "com.grab.android.sample" - minSdk = MIN_SDK - targetSdk = TARGET_SDK - } - JAVA_VERSION - - compileOptions { - sourceCompatibility = JAVA_VERSION - targetCompatibility = JAVA_VERSION - } - } - - tasks.withType(KotlinCompile::class.java).configureEach { - kotlinOptions { - jvmTarget = JVM_TARGET - } - } - } - } -} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidLibraryConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidLibraryConfigPlugin.kt deleted file mode 100644 index 7e196c2..0000000 --- a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/AndroidLibraryConfigPlugin.kt +++ /dev/null @@ -1,34 +0,0 @@ -package com.grab.sample.buildplugin - -import com.android.build.gradle.LibraryExtension -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -class AndroidLibraryConfigPlugin : Plugin { - override fun apply(project: Project) { - with(project) { - plugins.apply("com.android.library") - plugins.apply("kotlin-android") - - extensions.configure("android") { - compileSdk = COMPILE_SDK - defaultConfig { - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - consumerProguardFiles("consumer-rules.pro") - } - - compileOptions { - sourceCompatibility = JAVA_VERSION - targetCompatibility = JAVA_VERSION - } - - tasks.withType(KotlinCompile::class.java).configureEach { - kotlinOptions { - jvmTarget = JVM_TARGET - } - } - } - } - } -} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinLibraryConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinLibraryConfigPlugin.kt deleted file mode 100644 index 0847cb8..0000000 --- a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinLibraryConfigPlugin.kt +++ /dev/null @@ -1,33 +0,0 @@ -package com.grab.sample.buildplugin - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -class KotlinLibraryConfigPlugin : Plugin { - override fun apply(project: Project) { - with(project) { - plugins.apply("java-library") - plugins.apply("org.jetbrains.kotlin.jvm") - - extensions.getByType().apply { - sourceCompatibility = JAVA_VERSION - targetCompatibility = JAVA_VERSION - } - - extensions.getByType().apply { - jvmToolchain(JAVA_VERSION.toString().toInt()) - } - - tasks.withType().configureEach { - kotlinOptions { - jvmTarget = JVM_TARGET - } - } - } - } -} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinMultiplatformLibraryConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinMultiplatformLibraryConfigPlugin.kt deleted file mode 100644 index e86fa5a..0000000 --- a/sample/build-logic/src/main/java/com/grab/sample/buildplugin/KotlinMultiplatformLibraryConfigPlugin.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.grab.sample.buildplugin - -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByType -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -class KotlinMultiplatformLibraryConfigPlugin : Plugin { - override fun apply(project: Project) { - with(project) { - plugins.apply("org.jetbrains.kotlin.multiplatform") - - extensions.getByType().apply { - jvm() - jvmToolchain(JAVA_VERSION.toString().toInt()) - } - - tasks.withType().configureEach { - kotlinOptions { - jvmTarget = JVM_TARGET - } - } - } - } -} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/gradle/ConfigurablePlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/gradle/ConfigurablePlugin.kt new file mode 100644 index 0000000..713d351 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/gradle/ConfigurablePlugin.kt @@ -0,0 +1,10 @@ +package com.grab.sample.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project + +open class ConfigurablePlugin( + private val configuration: Project.() -> Unit +) : Plugin { + override fun apply(project: Project): Unit = configuration(project) +} \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/jvm/KmpConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/jvm/KmpConfigPlugin.kt new file mode 100644 index 0000000..f5d6f17 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/jvm/KmpConfigPlugin.kt @@ -0,0 +1,16 @@ +package com.grab.sample.jvm + +import com.grab.sample.BuildConfig +import com.grab.sample.gradle.ConfigurablePlugin +import org.gradle.kotlin.dsl.configure +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension + +class KmpConfigPlugin : ConfigurablePlugin({ + plugins.apply("org.jetbrains.kotlin.multiplatform") + + extensions.configure { + jvm() + } + + kotlinCommon() +}) \ No newline at end of file diff --git a/sample/build-logic/src/main/java/com/grab/sample/jvm/Kotlin.kt b/sample/build-logic/src/main/java/com/grab/sample/jvm/Kotlin.kt new file mode 100644 index 0000000..03efda1 --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/jvm/Kotlin.kt @@ -0,0 +1,58 @@ +/* + * MIT License + * + * Copyright (c) 2024. Grabtaxi Holdings Pte Ltd (GRAB), All rights reserved. + * + * + * 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.grab.sample.jvm + +import com.grab.sample.BuildConfig +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +fun Project.javaCommon() { + configure { + sourceCompatibility = BuildConfig.JAVA_VERSION + targetCompatibility = BuildConfig.JAVA_VERSION + } +} + +internal fun Project.kotlinCommon() { + + extensions.getByType().apply { + jvmToolchain(BuildConfig.JAVA_VERSION.toString().toInt()) + } + + tasks.withType().configureEach { + kotlinOptions { + jvmTarget = BuildConfig.JVM_TARGET + } + } +} + diff --git a/sample/build-logic/src/main/java/com/grab/sample/jvm/KotlinLibraryConfigPlugin.kt b/sample/build-logic/src/main/java/com/grab/sample/jvm/KotlinLibraryConfigPlugin.kt new file mode 100644 index 0000000..93e4dfb --- /dev/null +++ b/sample/build-logic/src/main/java/com/grab/sample/jvm/KotlinLibraryConfigPlugin.kt @@ -0,0 +1,39 @@ +/* + * MIT License + * + * Copyright (c) 2024. Grabtaxi Holdings Pte Ltd (GRAB), All rights reserved. + * + * + * 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.grab.sample.jvm + +import com.grab.sample.gradle.ConfigurablePlugin +import org.gradle.api.plugins.JavaPlugin +import org.gradle.kotlin.dsl.apply + +class KotlinLibraryConfigPlugin : ConfigurablePlugin({ + apply() + javaCommon() + apply(plugin = "org.jetbrains.kotlin.jvm") + kotlinCommon() +}) \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index d1f4884..bb8edbb 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -42,4 +42,5 @@ plugins { alias(libs.plugins.android.library) apply false alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.multiplatform) apply false } \ No newline at end of file diff --git a/sample/gradle.properties b/sample/gradle.properties index 30d6fd0..8114302 100644 --- a/sample/gradle.properties +++ b/sample/gradle.properties @@ -50,4 +50,6 @@ kotlin.code.style=official android.nonTransitiveRClass=true # Configuration on demand improves configuration time (Disabled due to incompatiblity with plugins) -org.gradle.configureondemand=false \ No newline at end of file +org.gradle.configureondemand=false + +kotlin.mpp.androidGradlePluginCompatibility.nowarn=true \ No newline at end of file diff --git a/sample/gradle/libs.versions.toml b/sample/gradle/libs.versions.toml index b2950b8..159a724 100644 --- a/sample/gradle/libs.versions.toml +++ b/sample/gradle/libs.versions.toml @@ -28,4 +28,5 @@ android-application = { id = "com.android.application", version.ref = "android-g kotlin-dsl = { id = "org.gradle.kotlin.kotlin-dsl", version.ref = "kotlin-dsl" } android-library = { id = "com.android.library", version.ref = "android-gradle-plugin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } \ No newline at end of file +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } diff --git a/sample/kotlin-multiplatform-module/build.gradle b/sample/kotlin-multiplatform-module/build.gradle index 6616907..a900a22 100644 --- a/sample/kotlin-multiplatform-module/build.gradle +++ b/sample/kotlin-multiplatform-module/build.gradle @@ -26,5 +26,5 @@ */ plugins { - id 'com.sample.kotlin.multiplatform.library' + id 'com.sample.kotlin.kmp' }