From 2af0cfc1ef911bd5d4ed3387edb2ea7c26214376 Mon Sep 17 00:00:00 2001 From: sean Date: Tue, 3 Sep 2024 20:21:19 -0400 Subject: [PATCH 1/6] Tidy up the maven publish --- build.gradle.kts | 1 - hiltcoroutines/build.gradle.kts | 26 +++++++++++++++++++++++++- settings.gradle.kts | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 80e13ed..30a9091 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,3 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { alias(libs.plugins.android.library) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false diff --git a/hiltcoroutines/build.gradle.kts b/hiltcoroutines/build.gradle.kts index 5217dc5..eb7af91 100644 --- a/hiltcoroutines/build.gradle.kts +++ b/hiltcoroutines/build.gradle.kts @@ -41,10 +41,34 @@ project.afterEvaluate { create("release") { from(components["release"]) - // values used for local maven repo, jitpack uses github release: groupId = "com.github.seanzor" artifactId = "hiltcoroutines" version = "0.0.4" + + pom { + name.set("HiltCoroutines") + description.set("A library for integrating Hilt with Coroutines.") + url.set("https://github.com/seanzor/hiltcoroutines") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("seanzor") + name.set("Sean") + email.set("connect@sean8.com") + } + } + scm { + connection.set("scm:git:github.com/seanzor/hiltcoroutines.git") + developerConnection.set("scm:git:ssh://github.com/seanzor/hiltcoroutines.git") + url.set("https://github.com/seanzor/hiltcoroutines") + } + } } } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 2a40b24..4bfde41 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,6 +9,7 @@ pluginManagement { } mavenCentral() gradlePluginPortal() + maven { url = uri("https://jitpack.io") } } } dependencyResolutionManagement { From fc1b0e346a7177fae437281a4b14f94d0f4dd098 Mon Sep 17 00:00:00 2001 From: sean Date: Tue, 3 Sep 2024 21:23:33 -0400 Subject: [PATCH 2/6] Create another attempt at structuring the artifacts WIP? --- hiltcoroutines/build.gradle.kts | 80 +++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/hiltcoroutines/build.gradle.kts b/hiltcoroutines/build.gradle.kts index eb7af91..7642748 100644 --- a/hiltcoroutines/build.gradle.kts +++ b/hiltcoroutines/build.gradle.kts @@ -35,45 +35,69 @@ android { } } -project.afterEvaluate { - publishing { - publications { - create("release") { - from(components["release"]) +publishing { + publications { + create("release") { + // Add the AAR file manually + artifact(layout.buildDirectory.file("outputs/aar/${project.name}-release.aar")) - groupId = "com.github.seanzor" - artifactId = "hiltcoroutines" - version = "0.0.4" + groupId = "com.github.seanzor" + artifactId = "hiltcoroutines" + version = "0.0.4" - pom { - name.set("HiltCoroutines") - description.set("A library for integrating Hilt with Coroutines.") - url.set("https://github.com/seanzor/hiltcoroutines") +// artifact(tasks["sourcesJar"]) +// artifact(tasks["javadocJar"]) - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("seanzor") - name.set("Sean") - email.set("connect@sean8.com") - } + pom { + name.set("HiltCoroutines") + description.set("A library for integrating Hilt with Coroutines.") + url.set("https://github.com/seanzor/hiltcoroutines") + + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") } - scm { - connection.set("scm:git:github.com/seanzor/hiltcoroutines.git") - developerConnection.set("scm:git:ssh://github.com/seanzor/hiltcoroutines.git") - url.set("https://github.com/seanzor/hiltcoroutines") + } + developers { + developer { + id.set("seanzor") + name.set("Sean") + email.set("connect@sean8.com") } } + scm { + connection.set("scm:git:github.com/seanzor/hiltcoroutines.git") + developerConnection.set("scm:git:ssh://github.com/seanzor/hiltcoroutines.git") + url.set("https://github.com/seanzor/hiltcoroutines") + } } } } } +tasks { + val sourcesJar by creating(Jar::class) { + archiveClassifier.set("sources") + from(android.sourceSets["main"].java.srcDirs) + } + + val javadoc by creating(Javadoc::class) { + source = fileTree(android.sourceSets["main"].java.srcDirs) + } + + val javadocJar by creating(Jar::class) { + archiveClassifier.set("javadoc") + from(javadoc.destinationDir) + } + + artifacts { + archives(sourcesJar) + archives(javadocJar) + } +} + + dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) From 5e8bddd21877e679471a0b7f4ee7d80fa43b6523 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 4 Sep 2024 14:30:53 -0400 Subject: [PATCH 3/6] Align all assets to be ready for publish - Update maven publisher config - Set minSDK to 21 - Add JDOC --- .github/workflows/release.yaml | 25 +++- README.md | 7 +- gradle.properties | 24 +--- gradle/libs.versions.toml | 2 + hiltcoroutines/build.gradle.kts | 95 +++++---------- .../seanzor/hiltcoroutines/AppDispatchers.kt | 15 --- .../di/CoroutineScopesModule.kt | 62 ---------- .../hiltcoroutines/di/DispatchersModule.kt | 26 ---- .../sean8/hiltcoroutines/AppDispatchers.kt | 30 +++++ .../di/CoroutineScopesModule.kt | 114 ++++++++++++++++++ .../hiltcoroutines/di/DispatchersModule.kt | 55 +++++++++ .../di/CoroutineScopesModuleTest.kt | 6 +- .../di/DispatchersModuleTest.kt | 6 +- 13 files changed, 264 insertions(+), 203 deletions(-) delete mode 100644 hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/AppDispatchers.kt delete mode 100644 hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModule.kt delete mode 100644 hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/DispatchersModule.kt create mode 100644 hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/AppDispatchers.kt create mode 100644 hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/CoroutineScopesModule.kt create mode 100644 hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/DispatchersModule.kt rename hiltcoroutines/src/test/java/com/{github/seanzor => sean8}/hiltcoroutines/di/CoroutineScopesModuleTest.kt (92%) rename hiltcoroutines/src/test/java/com/{github/seanzor => sean8}/hiltcoroutines/di/DispatchersModuleTest.kt (90%) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b30aed0..375a009 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -29,4 +29,27 @@ jobs: files: | hiltcoroutines/build/outputs/ env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + publish: + environment: + name: "MavenCentral" + + needs: Build + + runs-on: ubuntu-latest + timeout-minutes: 30 + + steps: + - uses: actions/checkout@v4 + + - name: Make Gradle executable + run: chmod +x ./gradlew + + - name: Upload library + run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache + + env: + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyPassword }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }} \ No newline at end of file diff --git a/README.md b/README.md index 76134a0..8373dbb 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,8 @@ Add the following dependency to your `build.gradle` file: ```kotlin -repositories { - mavenCentral() - maven { url = uri("https://jitpack.io") } -} - dependencies { - implementation("com.github.seanzor:hiltcoroutines:x.x.x") + implementation("com.sean8:hiltcoroutines:0.0.7") } ``` diff --git a/gradle.properties b/gradle.properties index 20e2a01..f3a869b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,23 +1,7 @@ -# Project-wide Gradle settings. -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. For more details, visit -# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects -# org.gradle.parallel=true -# AndroidX package structure to make it clearer which packages are bundled with the -# Android operating system, and which are packaged with your app's APK -# https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true -# Kotlin code style for this project: "official" or "obsolete": kotlin.code.style=official -# Enables namespacing of each library's R class so that its R class includes only the -# resources declared in the library itself and none from the library's dependencies, -# thereby reducing the size of the R class for that library -android.nonTransitiveRClass=true \ No newline at end of file +android.nonTransitiveRClass=true + +SONATYPE_HOST=CENTRAL_PORTAL +RELEASE_SIGNING_ENABLED=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 71e43a5..2763336 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,6 +8,7 @@ appcompat = "1.7.0" kotlinxCoroutinesCore = "1.6.0" ksp = "2.0.0-1.0.21" robolectric = "4.12.2" +custom-maven-publish = "0.29.0" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } @@ -24,3 +25,4 @@ robolectric = { group = "org.robolectric", name = "robolectric", version.ref = " jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } android-library = { id = "com.android.library", version.ref = "agp" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +custom-maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "custom-maven-publish" } diff --git a/hiltcoroutines/build.gradle.kts b/hiltcoroutines/build.gradle.kts index 7642748..55325d9 100644 --- a/hiltcoroutines/build.gradle.kts +++ b/hiltcoroutines/build.gradle.kts @@ -2,15 +2,15 @@ plugins { alias(libs.plugins.android.library) alias(libs.plugins.jetbrains.kotlin.android) alias(libs.plugins.ksp) - `maven-publish` + alias(libs.plugins.custom.maven.publish) } android { - namespace = "com.github.seanzor.hiltcoroutines" + namespace = "com.sean8.hiltcoroutines" compileSdk = 34 defaultConfig { - minSdk = 24 + minSdk = 21 testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } @@ -27,77 +27,38 @@ android { kotlinOptions { jvmTarget = "1.8" } - - publishing { - singleVariant("release") { - withSourcesJar() - } - } } -publishing { - publications { - create("release") { - // Add the AAR file manually - artifact(layout.buildDirectory.file("outputs/aar/${project.name}-release.aar")) - - groupId = "com.github.seanzor" - artifactId = "hiltcoroutines" - version = "0.0.4" - -// artifact(tasks["sourcesJar"]) -// artifact(tasks["javadocJar"]) - - pom { - name.set("HiltCoroutines") - description.set("A library for integrating Hilt with Coroutines.") - url.set("https://github.com/seanzor/hiltcoroutines") - - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("seanzor") - name.set("Sean") - email.set("connect@sean8.com") - } - } - scm { - connection.set("scm:git:github.com/seanzor/hiltcoroutines.git") - developerConnection.set("scm:git:ssh://github.com/seanzor/hiltcoroutines.git") - url.set("https://github.com/seanzor/hiltcoroutines") - } +mavenPublishing { + coordinates("com.sean8", "hiltcoroutines", "0.0.7") + + pom { + name.set("HiltCoroutines") + description.set("A library for integrating Hilt with Coroutines.") + inceptionYear.set("2023") + url.set("https://github.com/seanzor/hiltcoroutines/") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + distribution.set("repo") } } + developers { + developer { + id.set("Sean8") + name.set("Sean Katz") + url.set("https://sean8.com") + } + } + scm { + url.set("https://github.com/seanzor/hiltcoroutines/") + connection.set("scm:git:git://github.com/seanzor/hiltcoroutines.git") + developerConnection.set("scm:git:ssh://git@github.com/seanzor/hiltcoroutines.git") + } } } -tasks { - val sourcesJar by creating(Jar::class) { - archiveClassifier.set("sources") - from(android.sourceSets["main"].java.srcDirs) - } - - val javadoc by creating(Javadoc::class) { - source = fileTree(android.sourceSets["main"].java.srcDirs) - } - - val javadocJar by creating(Jar::class) { - archiveClassifier.set("javadoc") - from(javadoc.destinationDir) - } - - artifacts { - archives(sourcesJar) - archives(javadocJar) - } -} - - dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) diff --git a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/AppDispatchers.kt b/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/AppDispatchers.kt deleted file mode 100644 index cb1c51c..0000000 --- a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/AppDispatchers.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.seanzor.hiltcoroutines - -import javax.inject.Qualifier -import kotlin.annotation.AnnotationRetention.RUNTIME - -@Suppress("unused") -@Qualifier -@Retention(RUNTIME) -annotation class Dispatcher(val appDispatcher: AppDispatchers) - -enum class AppDispatchers { - Default, - IO, - Main, -} \ No newline at end of file diff --git a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModule.kt b/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModule.kt deleted file mode 100644 index 3938d37..0000000 --- a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModule.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.github.seanzor.hiltcoroutines.di - -import com.github.seanzor.hiltcoroutines.AppDispatchers -import com.github.seanzor.hiltcoroutines.Dispatcher -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Job -import kotlinx.coroutines.SupervisorJob -import javax.inject.Qualifier -import javax.inject.Singleton - -@Retention(AnnotationRetention.RUNTIME) -@Qualifier -annotation class ApplicationScope - -@Retention(AnnotationRetention.RUNTIME) -@Qualifier -annotation class IOScope - -@Retention(AnnotationRetention.RUNTIME) -@Qualifier -annotation class MainScope - -@Retention(AnnotationRetention.RUNTIME) -@Qualifier -annotation class StrictScope - -@Module -@InstallIn(SingletonComponent::class) -object CoroutineScopesModule { - @Provides - @Singleton - @ApplicationScope - fun providesApplicationScope( - @Dispatcher(AppDispatchers.Default) dispatcher: CoroutineDispatcher - ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) - - @Provides - @Singleton - @IOScope - fun providesIOScope( - @Dispatcher(AppDispatchers.IO) dispatcher: CoroutineDispatcher - ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) - - @Provides - @Singleton - @MainScope - fun providesMainScope( - @Dispatcher(AppDispatchers.Main) dispatcher: CoroutineDispatcher - ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) - - @Provides - @Singleton - @StrictScope - fun providesStrictScope( - @Dispatcher(AppDispatchers.Default) dispatcher: CoroutineDispatcher - ): CoroutineScope = CoroutineScope(Job() + dispatcher) -} \ No newline at end of file diff --git a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/DispatchersModule.kt b/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/DispatchersModule.kt deleted file mode 100644 index a538159..0000000 --- a/hiltcoroutines/src/main/kotlin/com/github/seanzor/hiltcoroutines/di/DispatchersModule.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.seanzor.hiltcoroutines.di - -import com.github.seanzor.hiltcoroutines.AppDispatchers -import com.github.seanzor.hiltcoroutines.Dispatcher -import dagger.Module -import dagger.Provides -import dagger.hilt.InstallIn -import dagger.hilt.components.SingletonComponent -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.Dispatchers - -@Module -@InstallIn(SingletonComponent::class) -object DispatchersModule { - @Provides - @Dispatcher(AppDispatchers.IO) - fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO - - @Provides - @Dispatcher(AppDispatchers.Default) - fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default - - @Provides - @Dispatcher(AppDispatchers.Main) - fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main -} \ No newline at end of file diff --git a/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/AppDispatchers.kt b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/AppDispatchers.kt new file mode 100644 index 0000000..8fad57a --- /dev/null +++ b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/AppDispatchers.kt @@ -0,0 +1,30 @@ +package com.sean8.hiltcoroutines + +import javax.inject.Qualifier +import kotlin.annotation.AnnotationRetention.RUNTIME + +/** + * Qualifier annotation for specifying different Coroutine Dispatchers. + * + * This is used to distinguish between the different [AppDispatchers] provided + * by the dependency injection framework using Hilt. + * + * @property appDispatcher The dispatcher type from [AppDispatchers]. + */ +@Suppress("unused") +@Qualifier +@Retention(RUNTIME) +annotation class Dispatcher(val appDispatcher: AppDispatchers) + +/** + * Enum representing the available coroutine dispatchers in the application. + * + * - [Default] corresponds to [Dispatchers.Default]. + * - [IO] corresponds to [Dispatchers.IO]. + * - [Main] corresponds to [Dispatchers.Main]. + */ +enum class AppDispatchers { + Default, + IO, + Main, +} diff --git a/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/CoroutineScopesModule.kt b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/CoroutineScopesModule.kt new file mode 100644 index 0000000..bd51d2d --- /dev/null +++ b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/CoroutineScopesModule.kt @@ -0,0 +1,114 @@ +package com.sean8.hiltcoroutines.di + +import com.sean8.hiltcoroutines.AppDispatchers +import com.sean8.hiltcoroutines.Dispatcher +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import javax.inject.Qualifier +import javax.inject.Singleton + +/** + * Qualifier annotation for distinguishing the application's [CoroutineScope]. + */ +@Retention(AnnotationRetention.RUNTIME) +@Qualifier +annotation class ApplicationScope + +/** + * Qualifier annotation for distinguishing the IO [CoroutineScope]. + */ +@Retention(AnnotationRetention.RUNTIME) +@Qualifier +annotation class IOScope + +/** + * Qualifier annotation for distinguishing the Main [CoroutineScope]. + */ +@Retention(AnnotationRetention.RUNTIME) +@Qualifier +annotation class MainScope + +/** + * Qualifier annotation for a strict [CoroutineScope] using [Job]. + */ +@Retention(AnnotationRetention.RUNTIME) +@Qualifier +annotation class StrictScope + +/** + * Hilt module for providing different coroutine scopes. + * + * This module provides various CoroutineScopes based on the provided [CoroutineDispatcher] + * and whether a [SupervisorJob] or [Job] is used. + */ +@Module +@InstallIn(SingletonComponent::class) +object CoroutineScopesModule { + + /** + * Provides the application-wide [CoroutineScope] with a [SupervisorJob]. + * + * This scope uses the [AppDispatchers.Default] dispatcher for CPU-bound tasks. + * + * @param dispatcher The [CoroutineDispatcher] to be used for the application scope. + * @return The application-wide [CoroutineScope]. + */ + @Provides + @Singleton + @ApplicationScope + fun providesApplicationScope( + @Dispatcher(AppDispatchers.Default) dispatcher: CoroutineDispatcher + ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) + + /** + * Provides the IO-bound [CoroutineScope] with a [SupervisorJob]. + * + * This scope uses the [AppDispatchers.IO] dispatcher for IO-bound tasks. + * + * @param dispatcher The [CoroutineDispatcher] to be used for the IO scope. + * @return The IO-bound [CoroutineScope]. + */ + @Provides + @Singleton + @IOScope + fun providesIOScope( + @Dispatcher(AppDispatchers.IO) dispatcher: CoroutineDispatcher + ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) + + /** + * Provides the Main-thread [CoroutineScope] with a [SupervisorJob]. + * + * This scope uses the [AppDispatchers.Main] dispatcher for UI-bound tasks. + * + * @param dispatcher The [CoroutineDispatcher] to be used for the Main scope. + * @return The Main-thread [CoroutineScope]. + */ + @Provides + @Singleton + @MainScope + fun providesMainScope( + @Dispatcher(AppDispatchers.Main) dispatcher: CoroutineDispatcher + ): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher) + + /** + * Provides a strict [CoroutineScope] with a [Job], without the benefits of a [SupervisorJob]. + * + * This scope uses the [AppDispatchers.Default] dispatcher and adheres to stricter cancellation + * behavior. + * + * @param dispatcher The [CoroutineDispatcher] to be used for the strict scope. + * @return The strict [CoroutineScope]. + */ + @Provides + @Singleton + @StrictScope + fun providesStrictScope( + @Dispatcher(AppDispatchers.Default) dispatcher: CoroutineDispatcher + ): CoroutineScope = CoroutineScope(Job() + dispatcher) +} \ No newline at end of file diff --git a/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/DispatchersModule.kt b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/DispatchersModule.kt new file mode 100644 index 0000000..c4b001b --- /dev/null +++ b/hiltcoroutines/src/main/kotlin/com/sean8/hiltcoroutines/di/DispatchersModule.kt @@ -0,0 +1,55 @@ +package com.sean8.hiltcoroutines.di + +import com.sean8.hiltcoroutines.AppDispatchers +import com.sean8.hiltcoroutines.Dispatcher +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.Dispatchers + +/** + * Hilt module for providing different coroutine dispatchers. + * + * This module is installed in the [SingletonComponent], making the provided dispatchers + * available as singleton instances throughout the application. + */ +@Module +@InstallIn(SingletonComponent::class) +object DispatchersModule { + + /** + * Provides the [Dispatchers.IO] dispatcher. + * + * This dispatcher is optimized for IO-bound operations such as reading or writing to files + * or databases, and network requests. + * + * @return The [Dispatchers.IO] instance. + */ + @Provides + @Dispatcher(AppDispatchers.IO) + fun providesIODispatcher(): CoroutineDispatcher = Dispatchers.IO + + /** + * Provides the [Dispatchers.Default] dispatcher. + * + * This dispatcher is optimized for CPU-bound operations, such as processing large data sets. + * + * @return The [Dispatchers.Default] instance. + */ + @Provides + @Dispatcher(AppDispatchers.Default) + fun providesDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default + + /** + * Provides the [Dispatchers.Main] dispatcher. + * + * This dispatcher is optimized for main-thread UI operations. + * + * @return The [Dispatchers.Main] instance. + */ + @Provides + @Dispatcher(AppDispatchers.Main) + fun providesMainDispatcher(): CoroutineDispatcher = Dispatchers.Main +} diff --git a/hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModuleTest.kt b/hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/CoroutineScopesModuleTest.kt similarity index 92% rename from hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModuleTest.kt rename to hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/CoroutineScopesModuleTest.kt index 6fddedc..edcd726 100644 --- a/hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/CoroutineScopesModuleTest.kt +++ b/hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/CoroutineScopesModuleTest.kt @@ -1,7 +1,7 @@ -package com.github.seanzor.hiltcoroutines.di +package com.sean8.hiltcoroutines.di -import com.github.seanzor.hiltcoroutines.AppDispatchers -import com.github.seanzor.hiltcoroutines.Dispatcher +import com.sean8.hiltcoroutines.AppDispatchers +import com.sean8.hiltcoroutines.Dispatcher import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.HiltTestApplication diff --git a/hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/DispatchersModuleTest.kt b/hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/DispatchersModuleTest.kt similarity index 90% rename from hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/DispatchersModuleTest.kt rename to hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/DispatchersModuleTest.kt index ce93a98..3135e75 100644 --- a/hiltcoroutines/src/test/java/com/github/seanzor/hiltcoroutines/di/DispatchersModuleTest.kt +++ b/hiltcoroutines/src/test/java/com/sean8/hiltcoroutines/di/DispatchersModuleTest.kt @@ -1,7 +1,7 @@ -package com.github.seanzor.hiltcoroutines.di +package com.sean8.hiltcoroutines.di -import com.github.seanzor.hiltcoroutines.AppDispatchers -import com.github.seanzor.hiltcoroutines.Dispatcher +import com.sean8.hiltcoroutines.AppDispatchers +import com.sean8.hiltcoroutines.Dispatcher import dagger.hilt.android.testing.HiltAndroidRule import dagger.hilt.android.testing.HiltAndroidTest import dagger.hilt.android.testing.HiltTestApplication From 1edf16f65a6b211dce7fdbf12fed0b421f529b20 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 4 Sep 2024 14:51:40 -0400 Subject: [PATCH 4/6] Update the JDK for the publish step --- .github/workflows/release.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 375a009..6f631d1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -42,6 +42,12 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'adopt' + - name: Make Gradle executable run: chmod +x ./gradlew From 647a5db1d02b55084880033e06624dfdc5b60b19 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 4 Sep 2024 14:57:57 -0400 Subject: [PATCH 5/6] Cache gradle --- .github/workflows/release.yaml | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6f631d1..d3e422b 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -13,6 +13,14 @@ jobs: - name: Checkout code uses: actions/checkout@v3 + - name: Cache Gradle + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + - name: Set up JDK 17 uses: actions/setup-java@v3 with: @@ -30,11 +38,12 @@ jobs: hiltcoroutines/build/outputs/ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + publish: environment: name: "MavenCentral" - needs: Build + needs: build runs-on: ubuntu-latest timeout-minutes: 30 @@ -42,6 +51,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: Cache Gradle + uses: actions/cache@v3 + with: + path: ~/.gradle/caches + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + - name: Set up JDK 17 uses: actions/setup-java@v3 with: @@ -58,4 +75,4 @@ jobs: ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKey }} ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_signingInMemoryKeyPassword }} ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralUsername }} - ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }} \ No newline at end of file + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.ORG_GRADLE_PROJECT_mavenCentralPassword }} From e057d6fa928eb2356a8c3a9f42074959f85f6dd9 Mon Sep 17 00:00:00 2001 From: sean Date: Wed, 4 Sep 2024 15:03:49 -0400 Subject: [PATCH 6/6] Fix GH env name --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d3e422b..946a89a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -41,7 +41,7 @@ jobs: publish: environment: - name: "MavenCentral" + name: "maven_publish" needs: build