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

Fix Koin Gradle plugin #817

Merged
merged 5 commits into from
Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
32 changes: 30 additions & 2 deletions koin-projects/examples/androidx-samples/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
// classpath "org.koin:koin-gradle-plugin:$koin_version"
}
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

apply from: '../../gradle/versions-examples.gradle'
//apply plugin: 'koin'

android {
compileSdkVersion android_target_version
Expand All @@ -14,13 +25,21 @@ android {
applicationId "org.koin.sample.androidx"
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

testOptions {
unitTests.all {
useJUnit()
}
}
}

dependencies {
Expand All @@ -30,9 +49,18 @@ dependencies {
implementation project(":koin-androidx-fragment")
implementation 'junit:junit:4.12'

testImplementation project(":koin-test")

testImplementation 'junit:junit:4.12'
testImplementation "androidx.test:core:1.1.1"
testImplementation "androidx.test.ext:junit:1.1.1"
testImplementation "org.robolectric:robolectric:4.2.1"
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation "androidx.appcompat:appcompat:$androidx_lib_version"
implementation "androidx.lifecycle:lifecycle-extensions:$android_arch_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-savedstate:$androidx_savedstate"
implementation "org.jetbrains.anko:anko-commons:$anko_version"

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import org.junit.Test
import org.junit.experimental.categories.Category
import org.koin.core.parameter.parametersOf
import org.koin.sample.androidx.components.mvp.FactoryPresenter
import org.koin.sample.androidx.components.mvp.ScopedPresenter
import org.koin.sample.androidx.di.appModule
import org.koin.sample.androidx.di.mvpModule
import org.koin.sample.androidx.di.mvvmModule
import org.koin.test.category.CheckModuleTest
import org.koin.test.check.checkModules

@Category(CheckModuleTest::class)
class CheckModulesTest {

@Test
fun `test DI modules`() = checkModules(
parameters = {
create<FactoryPresenter> { parametersOf("_ID_") }
create<ScopedPresenter> { parametersOf("_ID_") }
}
) {
modules(appModule + mvpModule + mvvmModule)// + mvpModule + mvvmModule + scopeModule)
arnaudgiuliani marked this conversation as resolved.
Show resolved Hide resolved
}

}
6 changes: 2 additions & 4 deletions koin-projects/examples/coffee-maker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ buildscript {
mavenCentral()
jcenter()
}
// dependencies {
dependencies {
// classpath "org.koin:koin-gradle-plugin:$koin_version"
// }
}
}

apply plugin: 'kotlin'
//apply plugin: 'koin'

archivesBaseName = 'example-coffee-maker'

dependencies {
implementation project(":koin-core")
testImplementation project(":koin-test")
Expand Down
2 changes: 1 addition & 1 deletion koin-projects/gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ext {
// Koin
koin_version = '2.1.5'
koin_version = '2.1.6-alpha-1'

// Kotlin
kotlin_version = '1.3.70'
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions koin-projects/koin-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = 'Koin - simple dependency injection for Kotlin - ' + archivesBaseN
dependencies {
// Kt
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile project(":koin-test")
compile gradleApi()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@ package org.koin.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.UnknownTaskException
import org.gradle.api.tasks.testing.Test

open class KoinPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.tasks.register("checkModules", Test::class.java) {test ->
test.testLogging {
it.showStandardStreams = true
project.tasks.register("checkAndroidModules") { test ->
test.dependsOn("testDebugUnitTest")
}

project.tasks.register("checkModules", Test::class.java) { test: Test? ->
try {
test?.let {
test.testLogging {
it.showStandardStreams = true
}
test.useJUnit {
it.includeCategories("org.koin.test.category.CheckModuleTest")
}
}
} catch (e: Exception) {
e.printStackTrace()
}
test.useJUnit {
it.includeCategories("org.koin.test.category.CheckModuleTest")
}

project.gradle.taskGraph.whenReady { taskGraph ->
try {
val testTask = project.tasks.getByName("testDebugUnitTest") as? Test?
testTask?.let {
if (taskGraph.hasTask(project.tasks.getByName("checkAndroidModules"))) {
testTask.testLogging {
it.showStandardStreams = true
}
testTask.useJUnit {
it.includeCategories("org.koin.test.category.CheckModuleTest")
}
} else {
System.err.println("can't register checkAndroidModules")
}
}
} catch (e: UnknownTaskException) {
// nothing to do with testDebugUnitTest
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Expand Down