From 9a91124b6b4845bf573ae402fc62f0fe7cb67330 Mon Sep 17 00:00:00 2001 From: Eva Tatarka Date: Wed, 12 Jun 2024 14:17:23 -0700 Subject: [PATCH] prepare release 0.7.0 --- CHANGELOG.md | 25 +++++++++++++++++- README.md | 53 ++++++++++++++++++++++++++------------- docs/multiplatform.md | 10 ++++---- gradle/libs.versions.toml | 2 +- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbb84ba7..32451b3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.7.0] 2024-06-12 ### Changed - `@Scope` annotations now take arguments into account. This means for example, if you have @@ -43,10 +43,33 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. } ``` This behaves the same as `javax.inject.Qualifier` does when you have `me.tatarka.inject.enableJavaxAnnotations=true`. +- Added a new `@KmpComponentCreate` annotation for nicer multiplatform support. This allows you to create component + instances from common code when generating platform-specific outputs. + ```kotlin + // src/commonMain + @Component + abstract class MyKmpComponent + + @KmpComponentCreate + expect fun createKmp(): MyKmpComponent + ``` + see the new [multiplatform docs](docs/multiplatform.md) for more details. +- You can now use an `@Inject` annotation on an inner class provided the outer class can be provided. + ```kotlin + @Inject class Outer { @Inject inner class Inner } + + @Component abstract class MyComponent { abstract val inner: Outer.Inner } + ``` ### Removed - The KAPT backend is removed, please migrate to KSP if you haven't already. +### Fixed +- Fixed cases of invalid code generation (#321, #337, #313). +- Fixed an exception thrown on KSP2 when running multiple rounds (google/ksp#1854). +- Fixed various issues with handling method overrides in components (#309, #375) +- Allow scope annotations on both an interface and component implementation if they are the same scope (#320). + ## [0.6.3] 2023-09-02 ### Fixed diff --git a/README.md b/README.md index 8f67d110..6aeadf04 100644 --- a/README.md +++ b/README.md @@ -64,22 +64,8 @@ repositories { } dependencies { - ksp("me.tatarka.inject:kotlin-inject-compiler-ksp:0.6.3") - implementation("me.tatarka.inject:kotlin-inject-runtime:0.6.3") -} -``` - -### or with KAPT (deprecated) - -```groovy -plugins { - id("org.jetbrains.kotlin.jvm") version "1.9.0" - id("org.jetbrains.kotlin.kapt") version "1.9.0" -} - -dependencies { - kapt("me.tatarka.inject:kotlin-inject-compiler-kapt:0.6.3") - implementation("me.tatarka.inject:kotlin-inject-runtime:0.6.3") + ksp("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0") + implementation("me.tatarka.inject:kotlin-inject-runtime:0.7.0") } ``` @@ -187,10 +173,41 @@ val parent = ParentComponent::class.create() val child = ChildComponent::class.create(parent) ``` +### Qualifiers + +If you have multiple instances of the same type you want to differentiate, you can use a `@Qualifier`. They will be +treated as separate types for the purposes of injection. They can be placed either on the variable or the type. + +```kotlin +@Qualifier +@Target( + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.FUNCTION, + AnnotationTarget.VALUE_PARAMETER, + AnnotationTarget.TYPE +) +annotation class Named(val value: String) + +@Component +abstract class MyComponent { + @Provides + fun dep1(): @Named("one") Dep = Dep("one") + + @Provides + fun dep2(): @Named("two") Dep = Dep("two") + + @Provides + fun provides(@Named("one") dep1: Dep, @Named("two") dep2: Dep): Thing = Thing(dep1, dep2) +} + +@Inject +class InjectedClass(@Named("one") dep1: Dep, @Named("two") dep2: Dep) +``` + ### Type Alias Support -If you have multiple instances of the same type you want to differentiate, you can use type aliases. They will be -treated as separate types for the purposes of injection. +Alternatively different typealises will be treated as different types. (Note: this is going away in a future release, so +consider using a `@Qualifier` annotation instead. There will be a migration path.) ```kotlin typealias Dep1 = Dep diff --git a/docs/multiplatform.md b/docs/multiplatform.md index f518a821..6a016ea7 100644 --- a/docs/multiplatform.md +++ b/docs/multiplatform.md @@ -40,7 +40,7 @@ Add the runtime dependency in commonMain sourceSets { commonMain { dependencies { - implementation("me.tatarka.inject:kotlin-inject-runtime-kmp:0.7.0-SNAPSHOT") + implementation("me.tatarka.inject:kotlin-inject-runtime-kmp:0.7.0") } } } @@ -67,10 +67,10 @@ dependencies { kspCommonMainMetadata(libs.kotlinInject) // 2. Configure code generation into each KMP target source set - kspAndroid("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0-SNAPSHOT") - kspIosX64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0-SNAPSHOT") - kspIosArm64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0-SNAPSHOT") - kspIosSimulatorArm64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0-SNAPSHOT") + kspAndroid("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0") + kspIosX64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0") + kspIosArm64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0") + kspIosSimulatorArm64("me.tatarka.inject:kotlin-inject-compiler-ksp:0.7.0") } ``` diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 93ed77f4..53686919 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -kotlin-inject = "0.7.0-SNAPSHOT" +kotlin-inject = "0.7.0" kotlin = "1.9.24" ksp = "1.9.24-1.0.20" kotlinpoet = "1.16.0"