diff --git a/docs/reference/koin-annotations/start.md b/docs/reference/koin-annotations/start.md index 5b12fda..a0ededf 100644 --- a/docs/reference/koin-annotations/start.md +++ b/docs/reference/koin-annotations/start.md @@ -51,7 +51,7 @@ The Koin compiler offers some options to configure. Following the official doc, ### Compile Safety - check your Koin config at compile time (since 1.3.0) -Koin Annotations allows the compiler plugin to verify yout Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module: +Koin Annotations allows the compiler plugin to verify your Koin configuration at compile time. This can be activated with the following Ksp options, to add to your Gradle module: ```groovy // in build.gradle or build.gradle.kts @@ -78,7 +78,7 @@ class MyPresenter(@Provided val provided : MyProvidedComponent) ### Disabling Default Module (since 1.3.0) -By default, the Koibn compiler detect any definition not bound to a module and put it in a "default mmodule", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option: +By default, the Koin compiler detect any definition not bound to a module and put it in a "default module", a Koin module generated at the root of your project. You can disable the use and generation of default module with the following option: ```groovy // in build.gradle or build.gradle.kts diff --git a/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt b/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt index aec9e94..2fe888e 100644 --- a/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt +++ b/examples/android-coffee-maker/src/test/java/AndroidModuleTest.kt @@ -1,6 +1,7 @@ package org.koin.sample.androidx import RootModule +import it.example.component.ExampleSingleton import org.junit.Test import org.koin.core.context.startKoin import org.koin.core.context.stopKoin @@ -38,6 +39,9 @@ class AndroidModuleTest { assert(koin.getOrNull() != null) assert(koin.getOrNull() != null) + assert(koin.getOrNull() != null) + + stopKoin() } } \ No newline at end of file diff --git a/examples/android-library/src/main/java/it/example/component/Example.kt b/examples/android-library/src/main/java/it/example/component/Example.kt new file mode 100644 index 0000000..61c6070 --- /dev/null +++ b/examples/android-library/src/main/java/it/example/component/Example.kt @@ -0,0 +1,12 @@ +package it.example.component + +import org.koin.core.annotation.ComponentScan +import org.koin.core.annotation.Module +import org.koin.core.annotation.Single + +@Module +@ComponentScan +class ExampleModule + +@Single +class ExampleSingleton \ No newline at end of file diff --git a/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt b/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt index dd4884d..87cc1a8 100644 --- a/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt +++ b/examples/android-library/src/main/java/org/koin/sample/android/library/CommonModule.kt @@ -1,8 +1,9 @@ package org.koin.sample.android.library +import it.example.component.ExampleModule import org.koin.core.annotation.ComponentScan import org.koin.core.annotation.Module -@Module +@Module(includes = [ExampleModule::class]) @ComponentScan class CommonModule \ No newline at end of file diff --git a/examples/gradle/libs.versions.toml b/examples/gradle/libs.versions.toml index b0375b4..90beffd 100644 --- a/examples/gradle/libs.versions.toml +++ b/examples/gradle/libs.versions.toml @@ -5,7 +5,7 @@ # Core kotlin = "1.9.24" koin = "3.5.6" -koinAnnotations = "1.4.0-RC4" +koinAnnotations = "1.4.0" ksp = "1.9.24-1.0.20" junit = "4.13.2" # Android diff --git a/projects/gradle.properties b/projects/gradle.properties index 85b6a64..22ff7e0 100644 --- a/projects/gradle.properties +++ b/projects/gradle.properties @@ -7,7 +7,7 @@ org.gradle.parallel=true #Kotlin kotlin.code.style=official #Koin -koinAnnotationsVersion=1.4.0-RC4 +koinAnnotationsVersion=1.4.0 #Android android.useAndroidX=true androidMinSDK=14 diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt index 95c2223..11c0eb9 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/BuilderProcessor.kt @@ -82,13 +82,16 @@ class BuilderProcessor( //TODO Use Koin 4.0 ViewModel DSL @Deprecated("use isKoinComposeViewModelActive") private fun isComposeViewModelActive(): Boolean { - logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'") - return options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + val option = options.getOrDefault(USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + if (option) logger.warn("[Deprecated] 'USE_COMPOSE_VIEWMODEL' arg is deprecated. Please use 'KOIN_USE_COMPOSE_VIEWMODEL'") + return option } private fun isKoinComposeViewModelActive(): Boolean { - logger.warn("Activate Compose ViewModel for @KoinViewModel generation") - return options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + val option = + options.getOrDefault(KOIN_USE_COMPOSE_VIEWMODEL.name, "false") == true.toString() + if (option) logger.warn("Activate Compose ViewModel for @KoinViewModel generation") + return option } //TODO turn KOIN_DEFAULT_MODULE to false by default - Next Major version (breaking) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt index ff1d64b..b905177 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/DefinitionWriter.kt @@ -95,7 +95,7 @@ class DefinitionWriter( } private fun List.generateParamFunction(): String { - return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else "" + return if (any { it is KoinMetaData.DefinitionParameter.ParameterInject }) "params -> " else "_ -> " } private fun String?.generateQualifier(): String = when { diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt index c14cb4f..4b5dc15 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/KoinCodeGenerator.kt @@ -57,7 +57,7 @@ class KoinCodeGenerator( if (defaultModule.alreadyGenerated == false && hasDefaultDefinitions){ defaultModule.setCurrentDefinitionsToExternals() - DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule() + DefaultModuleWriter(codeGenerator, resolver, defaultModule, generateDefaultModule).writeModule(isComposeViewModelActive) } } diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt index 2999bd5..9b52a00 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/generator/ModuleWriter.kt @@ -49,7 +49,7 @@ abstract class ModuleWriter( private val generatedField = "${module.packageName("_")}_${module.name}" //TODO Remove isComposeViewModelActive with Koin 4 - fun writeModule(isComposeViewModelActive: Boolean = false) { + fun writeModule(isComposeViewModelActive: Boolean) { fileStream = createFileStream() definitionFactory = DefinitionWriterFactory(resolver, fileStream!!) @@ -88,11 +88,11 @@ abstract class ModuleWriter( } open fun writeHeader() { - write(MODULE_HEADER) + writeln(MODULE_HEADER) } open fun writeHeaderImports(isComposeViewModelActive: Boolean) { - write(generateImports(module.definitions, isComposeViewModelActive)) + writeln(generateImports(module.definitions, isComposeViewModelActive)) } private fun generateImports( @@ -108,7 +108,7 @@ abstract class ModuleWriter( keyword.import?.let { "import $it" } } } - .joinToString(separator = "\n", postfix = "\n") + .joinToString(separator = "\n") } open fun writeExternalDefinitions() { diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt index 15ba836..5e14060 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/scanner/ext/KspExt.kt @@ -138,7 +138,7 @@ internal fun List.getValueArgument(): String? { fun KSClassDeclaration.getPackageName() : String = packageName.asString() -val forbiddenKeywords = listOf("interface","it") +val forbiddenKeywords = listOf("in","interface") fun String.filterForbiddenKeywords() : String{ return split(".").joinToString(".") { if (it in forbiddenKeywords) "`$it`" else it diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt index 0d6e2e2..ca050e2 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/KoinTagWriter.kt @@ -119,7 +119,7 @@ class KoinTagWriter(val codeGenerator: CodeGenerator, val logger: KSPLogger) { fileStream: OutputStream, alreadyDeclared: java.util.ArrayList ) { - LOGGER.logging("tag: $tagName") +// LOGGER.logging("tag: $tagName") val tag = "public class $tagPrefix$tagName" fileStream.appendText("\n$tag") alreadyDeclared.add(tagName) diff --git a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt index b1842c0..903265b 100644 --- a/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt +++ b/projects/koin-ksp-compiler/src/jvmMain/kotlin/org/koin/compiler/verify/TypeWhiteList.kt @@ -8,5 +8,6 @@ internal val typeWhiteList = listOf( "androidx.appcompat.app.AppCompatActivity", "androidx.appcompat.app.AppCompatActivity", "androidx.fragment.app.Fragment", - "androidx.lifecycle.SavedStateHandle" + "androidx.lifecycle.SavedStateHandle", + "androidx.lifecycle.ViewModel" ) \ No newline at end of file