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

Setup network module #3

Merged
merged 4 commits into from
Jun 2, 2024
Merged
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
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ plugins {
alias(libs.plugins.compose.compiler) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.detekt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.ktorfit) apply false
}
12 changes: 7 additions & 5 deletions composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ plugins {
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.detekt)
alias(libs.plugins.ksp)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The search results indicate that the ksp plugin is included in multiple build.gradle.kts files, but there is no evidence of its usage in the Kotlin source files. This suggests that the ksp plugin might not be necessary for the Compose app.

  • build.gradle.kts: alias(libs.plugins.ksp) apply false
  • core/network/build.gradle.kts: alias(libs.plugins.ksp)
  • composeApp/build.gradle.kts: alias(libs.plugins.ksp)

Given this information, it appears that the ksp plugin is not actively used in the codebase.

Analysis chain

Verify the necessity of the ksp plugin in the Compose app. Ensure it is used effectively.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the use of the `ksp` plugin in the Compose app.

# Test: Search for `ksp` plugin usage in the Compose app. Expect: Effective use of the plugin.
rg --type kotlin "ksp" composeApp/build.gradle.kts

Length of output: 78



Script:

#!/bin/bash
# Description: Verify the use of the `ksp` plugin in the Compose app.

# Test: Search for `ksp` plugin usage in the Kotlin source files and other build configuration files.
rg --type kotlin "ksp" composeApp/src
rg --type kotlin "ksp" composeApp/buildSrc
rg --type kotlin "ksp" composeApp/settings.gradle.kts
rg --type kotlin "ksp" composeApp/gradle.properties

Length of output: 386



Script:

#!/bin/bash
# Description: Verify the use of the `ksp` plugin in the Compose app.

# Test: Search for `ksp` plugin usage in all Kotlin files in the repository.
rg --type kotlin "ksp"

Length of output: 193

}

kotlin {
Expand Down Expand Up @@ -34,6 +35,8 @@ kotlin {
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(projects.core.network)

implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
Expand All @@ -53,7 +56,7 @@ android {

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
sourceSets["main"].res.srcDirs("src/androidMain/res")
sourceSets["main"].resources.srcDirs("src/commonMain/resources")
sourceSets["main"].resources.srcDirs("src/commonMain/composeResources")

defaultConfig {
applicationId = "io.heroesofcode"
Expand Down Expand Up @@ -93,12 +96,11 @@ tasks.register<io.gitlab.arturbosch.detekt.Detekt>("detektCommon") {
config.setFrom(files("$rootDir/config/detekt/detekt.yml"))
setSource(files(
"$projectDir/src/commonMain/kotlin",
"$projectDir/src/commonTest/kotlin"
"$projectDir/src/commonTest/kotlin",
"$rootDir/core/network/src/commonMain/kotlin"
))
include("**/*.kt")
include("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
}


}
6 changes: 3 additions & 3 deletions composeApp/src/commonMain/kotlin/di/appModules.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package di

import org.koin.dsl.module

val appModule = module {}
val appModule = listOf(
networkModule
)
1 change: 1 addition & 0 deletions core/network/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
58 changes: 58 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.detekt)
alias(libs.plugins.ksp)
alias(libs.plugins.ktorfit)
}
Comment on lines +4 to +10
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The ktorfit plugin is correctly applied and necessary for the network module. However, there are no references to the ksp plugin being used in the codebase, suggesting it may be unnecessary.

  • ktorfit usage confirmed in core/network/build.gradle.kts and core/network/src/commonMain/kotlin/di/networkModule.kt.
  • No usage of ksp found beyond its declaration in core/network/build.gradle.kts.
Analysis chain

Ensure that all plugins, especially ksp and ktorfit, are necessary and correctly applied for the network module.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the application of plugins in the network module.

# Test: Search for plugin configurations in the network module. Expect: Correct plugin settings.
rg --type kotlin "plugins" core/network/build.gradle.kts

Length of output: 240



Script:

#!/bin/bash
# Description: Verify the necessity of ksp and ktorfit plugins in the network module.

# Test: Search for usage of ksp in the network module. Expect: References to ksp.
rg --type kotlin "ksp" core/network/

# Test: Search for usage of ktorfit in the network module. Expect: References to ktorfit.
rg --type kotlin "ktorfit" core/network/

Length of output: 354


kotlin {
androidTarget {
@OptIn(ExperimentalKotlinGradlePluginApi::class)
compilerOptions {
jvmTarget.set(JvmTarget.JVM_11)
}
}

listOf(
iosX64(),
iosArm64(),
iosSimulatorArm64()
).forEach { iosTarget ->
iosTarget.binaries.framework {
isStatic = true
}
}

sourceSets {
commonMain.dependencies {
implementation(libs.koin.core)
implementation(libs.koin.compose)

implementation(libs.ktor.core)
implementation(libs.ktor.logging)
implementation(libs.ktor.serialization)
implementation(libs.ktor.negotiation)
api(libs.ktorfit)
}
}
}

dependencies {
detektPlugins(libs.detekt.formatting)
}

android {
namespace = "io.heroesofcode.network"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
46 changes: 46 additions & 0 deletions core/network/src/commonMain/kotlin/di/networkModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package di

import de.jensklingenberg.ktorfit.Ktorfit
import io.ktor.client.HttpClient
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.plugins.logging.LogLevel
import io.ktor.client.plugins.logging.Logging
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import org.koin.dsl.module

const val BASE_URL = "https://example.com"

@OptIn(ExperimentalSerializationApi::class)
val networkModule = module {
single {
HttpClient {
install(Logging) {
level = LogLevel.ALL
}
Comment on lines +19 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The search results confirm that there are no environment-based configurations for logging levels in the codebase. The logging level is set to LogLevel.ALL unconditionally.

  • Consider adjusting the logging level or making it configurable based on the environment.
Analysis chain

Consider adjusting the logging level or making it configurable based on the environment.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify if there are environment-based configurations for logging levels.

# Test: Search for environment checks around logging configurations. Expect: Conditional logic based on environment.
rg --type kotlin "LogLevel" core/network/src/commonMain/kotlin/di/networkModule.kt

Length of output: 166



Script:

#!/bin/bash
# Description: Verify if there are environment-based configurations for logging levels across the entire codebase.

# Test: Search for environment checks around logging configurations. Expect: Conditional logic based on environment.
rg --type kotlin "LogLevel"

Length of output: 221


install(ContentNegotiation) {
json(
Json {
explicitNulls = false
ignoreUnknownKeys = true
isLenient = true
prettyPrint = true
encodeDefaults = true
classDiscriminator = "#class"
}
)
}
Comment on lines +23 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the necessity of Json settings such as prettyPrint and encodeDefaults for production use.

}
}

single {
val httpClient: HttpClient = get()

Ktorfit.Builder()
.httpClient(httpClient)
.baseUrl(BASE_URL)
.build()
}
}
25 changes: 20 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[versions]
agp = "8.2.0"
agp = "8.3.2"
android-compileSdk = "34"
android-minSdk = "24"
android-targetSdk = "34"
androidx-activityCompose = "1.9.0"
androidx-appcompat = "1.6.1"
androidx-appcompat = "1.7.0"
androidx-constraintlayout = "2.1.4"
androidx-core-ktx = "1.13.1"
androidx-espresso-core = "3.5.1"
Expand All @@ -13,9 +13,13 @@ androidx-test-junit = "1.1.5"
compose-plugin = "1.6.10"
junit = "4.13.2"
kotlin = "2.0.0"
koin = "3.4.3"
koin-compose = "1.0.4"
koin = "3.5.6"
koin-compose = "1.1.5"
detekt = "1.23.2"
ktor = "2.3.7"
okhttp = "4.12.0"
ksp = "2.0.0-1.0.21"
ktorfit = "2.0.0"

[libraries]
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
Expand All @@ -32,6 +36,15 @@ androidx-activity-compose = { module = "androidx.activity:activity-compose", ver
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koin-compose" }

ktor-darwin-ios = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
ktor-ios = { module = "io.ktor:ktor-client-ios", version.ref = "ktor" }
ktor-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-serialization = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktorfit = { group = "de.jensklingenberg.ktorfit", name = "ktorfit-lib", version.ref = "ktorfit" }

detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt"}

[plugins]
Expand All @@ -40,4 +53,6 @@ androidLibrary = { id = "com.android.library", version.ref = "agp" }
jetbrainsCompose = { id = "org.jetbrains.compose", version.ref = "compose-plugin" }
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
ktorfit = { id = "de.jensklingenberg.ktorfit", version.ref = "ktorfit" }
3 changes: 1 addition & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ dependencyResolutionManagement {
}

include(":composeApp")
include(":androidApp")
include(":shared")
include(":core:network")
Loading