-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from skydoves/feature/landscapist-kmp
Support KMP for the landscapist module
- Loading branch information
Showing
37 changed files
with
678 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ on: | |
jobs: | ||
lint: | ||
name: Spotless check | ||
runs-on: ubuntu-latest | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
|
@@ -23,7 +23,7 @@ jobs: | |
|
||
api_check: | ||
name: API check | ||
runs-on: ubuntu-latest | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
|
@@ -37,7 +37,7 @@ jobs: | |
|
||
build: | ||
name: Build and Tests | ||
runs-on: ubuntu-latest | ||
runs-on: macos-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ on: | |
jobs: | ||
publish: | ||
name: Snapshot build and publish | ||
runs-on: ubuntu-latest | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ on: | |
jobs: | ||
publish: | ||
name: Release build and publish | ||
runs-on: ubuntu-latest | ||
runs-on: macos-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
`kotlin-dsl` | ||
} | ||
|
||
group = "com.skydoves.landscapist.buildlogic" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
dependencies { | ||
compileOnly(libs.android.gradlePlugin) | ||
compileOnly(libs.kotlin.gradlePlugin) | ||
compileOnly(libs.spotless.gradlePlugin) | ||
compileOnly(libs.android.gradlePlugin) | ||
compileOnly(libs.kotlin.gradlePlugin) | ||
compileOnly(libs.spotless.gradlePlugin) | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
register("androidApplicationCompose") { | ||
id = "landscapist.application.compose" | ||
implementationClass = "AndroidApplicationComposeConventionPlugin" | ||
} | ||
register("androidLibraryCompose") { | ||
id = "landscapist.library.compose" | ||
implementationClass = "AndroidLibraryComposeConventionPlugin" | ||
} | ||
register("spotless") { | ||
id = "landscapist.spotless" | ||
implementationClass = "SpotlessConventionPlugin" | ||
} | ||
plugins { | ||
register("androidApplicationCompose") { | ||
id = "landscapist.application.compose" | ||
implementationClass = "AndroidApplicationComposeConventionPlugin" | ||
} | ||
register("androidLibraryCompose") { | ||
id = "landscapist.library.compose" | ||
implementationClass = "AndroidLibraryComposeConventionPlugin" | ||
} | ||
register("composeMultiplatformLibrary") { | ||
id = "landscapist.library.compose.multiplatform" | ||
implementationClass = "ComposeMultiplatformLibraryConventionPlugin" | ||
} | ||
register("spotless") { | ||
id = "landscapist.spotless" | ||
implementationClass = "SpotlessConventionPlugin" | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
build-logic/convention/src/main/kotlin/ComposeMultiplatformLibraryConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import com.android.build.gradle.LibraryExtension | ||
import com.skydoves.landscapist.configureAndroidCompose | ||
import com.skydoves.landscapist.configureComposeMultiplatform | ||
import com.skydoves.landscapist.configureKotlinAndroid | ||
import com.skydoves.landscapist.kotlinOptions | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.api.tasks.compile.JavaCompile | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
class ComposeMultiplatformLibraryConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
with(target) { | ||
pluginManager.apply("com.android.library") | ||
pluginManager.apply("org.jetbrains.kotlin.multiplatform") | ||
pluginManager.apply("org.jetbrains.compose") | ||
pluginManager.apply("com.vanniktech.maven.publish") | ||
pluginManager.apply("binary-compatibility-validator") | ||
pluginManager.apply("androidx.baselineprofile") | ||
|
||
extensions.configure<LibraryExtension> libraryExtension@{ | ||
extensions.configure<KotlinMultiplatformExtension> kmpExtension@{ | ||
configureComposeMultiplatform(this@libraryExtension, this@kmpExtension) | ||
} | ||
} | ||
|
||
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs") | ||
tasks.withType(JavaCompile::class.java).configureEach { | ||
this.targetCompatibility = libs.findVersion("jvmTarget").get().toString() | ||
this.sourceCompatibility = libs.findVersion("jvmTarget").get().toString() | ||
} | ||
|
||
dependencies { | ||
add("baselineProfile", project(":benchmark-landscapist")) | ||
} | ||
} | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
build-logic/convention/src/main/kotlin/com/skydoves/landscapist/ComposeMultiplatform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Designed and developed by 2020-2022 skydoves (Jaewoong Eum) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
@file:Suppress("UnstableApiUsage") | ||
|
||
package com.skydoves.landscapist | ||
|
||
import com.android.build.api.dsl.CommonExtension | ||
import java.io.File | ||
import org.gradle.api.Project | ||
import org.gradle.api.artifacts.VersionCatalogsExtension | ||
import org.gradle.kotlin.dsl.dependencies | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension | ||
|
||
/** | ||
* Configure Compose-Multiplatform-specific options | ||
*/ | ||
internal fun Project.configureComposeMultiplatform( | ||
commonExtension: CommonExtension<*, *, *, *, *>, | ||
kotlinMultiplatformExtension: KotlinMultiplatformExtension, | ||
) { | ||
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs") | ||
|
||
kotlinMultiplatformExtension.apply { | ||
androidTarget { publishLibraryVariants("release") } | ||
jvm("desktop") | ||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
macosX64() | ||
macosArm64() | ||
|
||
@Suppress("OPT_IN_USAGE") | ||
applyHierarchyTemplate { | ||
common { | ||
group("jvm") { | ||
withAndroidTarget() | ||
withJvm() | ||
} | ||
group("skia") { | ||
withJvm() | ||
group("darwin") { | ||
group("apple") { | ||
group("ios") { | ||
withIosX64() | ||
withIosArm64() | ||
withIosSimulatorArm64() | ||
} | ||
group("macos") { | ||
withMacosX64() | ||
withMacosArm64() | ||
} | ||
} | ||
withJs() | ||
} | ||
} | ||
} | ||
} | ||
|
||
explicitApi() | ||
} | ||
|
||
commonExtension.apply { | ||
buildFeatures { | ||
compose = true | ||
} | ||
|
||
composeOptions { | ||
kotlinCompilerExtensionVersion = | ||
libs.findVersion("androidxComposeCompiler").get().toString() | ||
} | ||
|
||
packaging { | ||
resources { | ||
excludes.add("/META-INF/{AL2.0,LGPL2.1}") | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun Project.buildComposeMetricsParameters(): List<String> { | ||
val metricParameters = mutableListOf<String>() | ||
val enableMetricsProvider = project.providers.gradleProperty("enableComposeCompilerMetrics") | ||
val enableMetrics = (enableMetricsProvider.orNull == "true") | ||
if (enableMetrics) { | ||
val metricsFolder = File(project.buildDir, "compose-metrics") | ||
metricParameters.add("-P") | ||
metricParameters.add( | ||
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=${metricsFolder.absolutePath}/compose_metrics" | ||
) | ||
} | ||
|
||
val enableReportsProvider = project.providers.gradleProperty("enableComposeCompilerReports") | ||
val enableReports = (enableReportsProvider.orNull == "true") | ||
if (enableReports) { | ||
val reportsFolder = File(project.buildDir, "compose-reports") | ||
metricParameters.add("-P") | ||
metricParameters.add( | ||
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=${reportsFolder.absolutePath}/compose_metrics" | ||
) | ||
} | ||
return metricParameters.toList() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.