Skip to content

Commit

Permalink
Add convention plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Jul 7, 2024
1 parent 4ccde1a commit 866c754
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.animation.AnimatedContentTransitionScope.SlideDirection
import androidx.compose.animation.EnterTransition
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.scaleIn
import androidx.compose.animation.scaleOut
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -131,10 +136,10 @@ class MainActivity : ComponentActivity() {
NavHost(
navController = navController,
startDestination = Screen.Home.name,
enterTransition = { fadeIn() + slideIntoContainer(SlideDirection.Start) },
exitTransition = { fadeOut() + slideOutOfContainer(SlideDirection.Start) },
popEnterTransition = { fadeIn() + slideIntoContainer(SlideDirection.End) },
popExitTransition = { fadeOut() + slideOutOfContainer(SlideDirection.End) },
// enterTransition = { MotionDefaults.sharedXAxisEnter(density) },
// exitTransition = { MotionDefaults.sharedXAxisExit(density) },
// popEnterTransition = { MotionDefaults.sharedXAxisPopEnter(density) },
// popExitTransition = { MotionDefaults.sharedXAxisPopExit(density) },
) {
composable(Screen.Home.name) {
HomeScreen(
Expand Down Expand Up @@ -262,4 +267,6 @@ class MainActivity : ComponentActivity() {
}
}
}


}
35 changes: 35 additions & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}

dependencies {
compileOnly(libs.android.gradle.plugin)
compileOnly(libs.kotlin.gradle.plugin)
compileOnly(libs.detekt)
compileOnly(libs.detekt.formatting)
}

gradlePlugin {
plugins {
register("library") {
id = "com.feedflow.library"
implementationClass = "KmpLibraryConventionPlugin"
}
register("detekt") {
id = "com.feedflow.detekt"
implementationClass = "DetektConventionPlugin"
}
}
}
43 changes: 43 additions & 0 deletions build-logic/convention/src/main/kotlin/DetektConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import io.gitlab.arturbosch.detekt.extensions.DetektExtension
import io.gitlab.arturbosch.detekt.extensions.DetektExtension.Companion.DEFAULT_SRC_DIR_JAVA
import io.gitlab.arturbosch.detekt.extensions.DetektExtension.Companion.DEFAULT_SRC_DIR_KOTLIN
import io.gitlab.arturbosch.detekt.extensions.DetektExtension.Companion.DEFAULT_TEST_SRC_DIR_JAVA
import io.gitlab.arturbosch.detekt.extensions.DetektExtension.Companion.DEFAULT_TEST_SRC_DIR_KOTLIN
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType

class DetektConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("io.gitlab.arturbosch.detekt")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

extensions.configure<DetektExtension> {
config.setFrom("$rootDir/build-config/detekt-config.yml")
parallel = true

source.setFrom(
files(
"src",
DEFAULT_SRC_DIR_JAVA,
DEFAULT_TEST_SRC_DIR_JAVA,
DEFAULT_SRC_DIR_KOTLIN,
DEFAULT_TEST_SRC_DIR_KOTLIN,
),
)

dependencies {
add("detektPlugins", libs.findLibrary("detekt-formatting").get())
add("detektPlugins", libs.findLibrary("detekt-compose-rules").get())
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import com.android.build.gradle.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class KmpLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.multiplatform")
apply("com.feedflow.detekt")
}
configure<KotlinMultiplatformExtension> {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
}
}

jvmToolchain(17)

jvm()

iosArm64()
iosSimulatorArm64()

@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}

configure<LibraryExtension> {
compileSdk = version("android-compile-sdk").toInt()
defaultConfig {
minSdk = version("android-min-sdk").toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
}
}

private fun Project.version(key: String): String = extensions
.getByType<VersionCatalogsExtension>()
.named("libs")
.findVersion(key)
.get()
.requiredVersion
}
14 changes: 14 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}

rootProject.name = "build-logic"
include(":convention")
57 changes: 29 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ plugins {
alias(libs.plugins.ksp) apply false
alias(libs.plugins.about.libraries) apply false
alias(libs.plugins.crashlytics) apply false
alias(libs.plugins.detekt)
alias(libs.plugins.detekt) apply false
alias(libs.plugins.org.jetbrains.kotlin.jvm) apply false
alias(libs.plugins.google.services) apply false
alias(libs.plugins.compose.compiler) apply false
Expand All @@ -26,33 +26,34 @@ tasks.register("clean", Delete::class) {
delete(layout.buildDirectory.get())
}

allprojects {
apply {
plugin(rootProject.libs.plugins.detekt.get().pluginId)
}

dependencies {
detektPlugins(rootProject.libs.io.gitlab.arturbosch.detekt.formatting) {
exclude(group = "org.slf4j", module = "slf4j-nop")
}
detektPlugins(rootProject.libs.detekt.compose.rules)
}

detekt {
source.setFrom(
files(
"src",
DEFAULT_SRC_DIR_JAVA,
DEFAULT_TEST_SRC_DIR_JAVA,
DEFAULT_SRC_DIR_KOTLIN,
DEFAULT_TEST_SRC_DIR_KOTLIN,
),
)
config.setFrom(rootProject.files("config/detekt/detekt.yml"))
parallel = true
autoCorrect = true
}
}
// todo: delete
//allprojects {
// apply {
// plugin(rootProject.libs.plugins.detekt.get().pluginId)
// }
//
// dependencies {
// detektPlugins(rootProject.libs.io.gitlab.arturbosch.detekt.formatting) {
// exclude(group = "org.slf4j", module = "slf4j-nop")
// }
// detektPlugins(rootProject.libs.detekt.compose.rules)
// }
//
// detekt {
// source.setFrom(
// files(
// "src",
// DEFAULT_SRC_DIR_JAVA,
// DEFAULT_TEST_SRC_DIR_JAVA,
// DEFAULT_SRC_DIR_KOTLIN,
// DEFAULT_TEST_SRC_DIR_KOTLIN,
// ),
// )
// config.setFrom(rootProject.files("config/detekt/detekt.yml"))
// parallel = true
// autoCorrect = true
// }
//}

subprojects {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
Expand Down
31 changes: 1 addition & 30 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,31 +1,11 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
alias(libs.plugins.compose.multiplatform)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.feedflow.library)
}

kotlin {
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}

jvmToolchain(17)

jvm("desktop")

iosArm64()
iosSimulatorArm64()

sourceSets {
all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
}

commonMain {
dependencies {
implementation(compose.runtime)
Expand All @@ -38,13 +18,4 @@ kotlin {

android {
namespace = "com.prof18.feedflow.core"
compileSdk = libs.versions.android.compile.sdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.min.sdk.get().toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
31 changes: 1 addition & 30 deletions database/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
plugins {
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.android.library)
alias(libs.plugins.feedflow.library)
alias(libs.plugins.sqldelight)
}

kotlin {
jvmToolchain(17)

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "17"
}
}
}

jvm()

iosArm64()
iosSimulatorArm64()

sourceSets {
all {
languageSettings.optIn("kotlin.experimental.ExperimentalObjCName")
}

commonMain {
dependencies {
implementation(project(":core"))
Expand Down Expand Up @@ -72,13 +52,4 @@ sqldelight {

android {
namespace = "com.prof18.feedflow.database"
compileSdk = libs.versions.android.compile.sdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.min.sdk.get().toInt()
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
Loading

0 comments on commit 866c754

Please sign in to comment.