Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update project build configuration and dependencies #514

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 59 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
/.idea
/local.properties
/build
/captures
.DS_Store
.externalNativeBuild
.gradle
# https://github.com/github/gitignore/blob/main/Android.gitignore
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
*.focus
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof

# https://github.com/github/gitignore/blob/main/Kotlin.gitignore
# Kotlin data directory
.kotlin/

# Compiled class file
*.class

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
10 changes: 10 additions & 0 deletions build-config/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
`kotlin-dsl`
}

dependencies {
compileOnly(libs.pluginartifact.android)
compileOnly(libs.pluginartifact.kotlin)
compileOnly(libs.pluginartifact.ktlint)
compileOnly(libs.pluginartifact.mavenPublish)
}
15 changes: 15 additions & 0 deletions build-config/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rootProject.name = "build-config"

dependencyResolutionManagement {
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
repositories {
mavenCentral()
google()
gradlePluginPortal()
}
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import com.android.build.gradle.BaseExtension
import extensions.isAndroidApplicationModule
import extensions.isAndroidLibraryModule
import extensions.isMultiplatformModule

configure<BaseExtension> {
compileSdkVersion(34)
defaultConfig {
minSdk = 21

if (isAndroidApplicationModule()) {
targetSdk = 34
versionCode = 1
versionName = "1.0"
}

if (isAndroidLibraryModule()) {
val proguardFilename = "consumer-rules.pro"
if (layout.projectDirectory.file(proguardFilename).asFile.exists()) {
consumerProguardFile(proguardFilename)
}
}
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

testOptions {
unitTests.all(Test::useJUnitPlatform)
}

if (isMultiplatformModule()) {
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

configure<KotlinProjectExtension> {
explicitApi()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import extensions.kotlinAndroid
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

kotlinAndroid {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import extensions.kotlinMultiplatform
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlinMultiplatform {
applyDefaultHierarchyTemplate {
common {
group("jvm") {
withCompilations {
it.target.targetName == "desktop" || it.target is KotlinAndroidTarget
}
}
group("nonAndroid") {
withCompilations {
it.target.targetName == "desktop"
}
}
}
}

androidTarget {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
jvm("desktop") {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import extensions.kotlinMultiplatform
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinAndroidTarget

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlinMultiplatform {
applyDefaultHierarchyTemplate {
common {
group("jvm") {
withCompilations {
it.target.targetName == "desktop" || it.target is KotlinAndroidTarget
}
}
group("nonAndroid") {
withJs()
withNative()
withWasmJs()
withCompilations {
it.target.targetName == "desktop"
}
}
group("commonWeb") {
withJs()
withWasmJs()
}
}
}

js(IR) {
browser()
}
@OptIn(ExperimentalWasmDsl::class)
wasmJs {
browser()
}

androidTarget {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
jvm("desktop") {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}

macosX64()
macosArm64()

iosArm64()
iosX64()
iosSimulatorArm64()

compilerOptions {
freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.jlleitschuh.gradle.ktlint.KtlintExtension

plugins.apply("org.jlleitschuh.gradle.ktlint")

configure<KtlintExtension> {
version.set("0.47.1")
disabledRules.set(setOf("filename"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

configure<KotlinProjectExtension> {
sourceSets.all {
languageSettings {
optIn("cafe.adriel.voyager.core.annotation.InternalVoyagerApi")
optIn("cafe.adriel.voyager.core.annotation.ExperimentalVoyagerApi")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost
import extensions.isMultiplatformModule
import extensions.kotlinMultiplatform

pluginManager.apply("com.vanniktech.maven.publish")

if (isMultiplatformModule()) {
kotlinMultiplatform {
androidTarget {
publishLibraryVariants("release")
}
}
}

group = "cafe.adriel.voyager"

configure<MavenPublishBaseExtension> {
publishToMavenCentral(host = SonatypeHost.S01, automaticRelease = true)
signAllPublications()

pom {
description = "A pragmatic navigation library for Jetpack Compose"
inceptionYear = "2021"
url = "https://github.com/adrielcafe/voyager"

licenses {
license {
name = "The MIT License"
url = "https://opensource.org/licenses/MIT"
distribution = "repo"
}
}

scm {
url = "https://github.com/adrielcafe/voyager"
connection = "scm:git:ssh://git@github.com/adrielcafe/voyager.git"
developerConnection = "scm:git:ssh://git@github.com/adrielcafe/voyager.git"
}

developers {
developer {
id = "adrielcafe"
name = "Adriel Cafe"
url = "https://github.com/adrielcafe/"
}
}
}
}
20 changes: 20 additions & 0 deletions build-config/src/main/kotlin/extensions/ProjectExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package extensions

import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

fun Project.hasPlugin(id: String) = plugins.hasPlugin(id)

fun Project.isAndroidLibraryModule(): Boolean = hasPlugin("com.android.library")

fun Project.isAndroidApplicationModule(): Boolean = hasPlugin("com.android.application")

fun Project.isMultiplatformModule() = hasPlugin("org.jetbrains.kotlin.multiplatform")

fun Project.kotlinMultiplatform(block: KotlinMultiplatformExtension.() -> Unit) =
extensions.configure<KotlinMultiplatformExtension>(block)

fun Project.kotlinAndroid(block: KotlinAndroidExtension.() -> Unit) =
extensions.configure<KotlinAndroidExtension>(block)
11 changes: 11 additions & 0 deletions build-config/src/main/kotlin/extensions/StringExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package extensions

import java.util.Locale

fun String.capitalize(): String = replaceFirstChar { firstChar ->
if (firstChar.isLowerCase()) {
firstChar.titlecase(Locale.getDefault())
} else {
toString()
}
}
14 changes: 14 additions & 0 deletions build-config/src/main/kotlin/samples-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("configure-android")
id("configure-opt-in")
id("configure-ktlint")
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.JVM_1_8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id("voyager-base-module")
id("configure-kotlin-android")
}
7 changes: 7 additions & 0 deletions build-config/src/main/kotlin/voyager-base-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
id("configure-android")
id("configure-opt-in")
id("configure-explicit-api")
id("configure-publishing")
id("configure-ktlint")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id("voyager-base-module")
id("configure-kotlin-desktop")
}
4 changes: 4 additions & 0 deletions build-config/src/main/kotlin/voyager-kmp-module.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id("voyager-base-module")
id("configure-kotlin-multiplatform")
}
Loading