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

Not clear checkModules instruction: Gradle Plugin fails with NPE #767

Closed
Perfomer opened this issue Apr 4, 2020 · 5 comments
Closed

Not clear checkModules instruction: Gradle Plugin fails with NPE #767

Perfomer opened this issue Apr 4, 2020 · 5 comments
Labels
status:accepted accepted to be developed type:issue
Milestone

Comments

@Perfomer
Copy link

Perfomer commented Apr 4, 2020

Describe the bug
I found out very interesting feature — checkModules Gradle plugin from Koin.
But unfortunately executing Gradle task "checkModules" leads to NPE.
I'm sure the guide is not clear.

That's the error:

C:\Development\Projects\Pet\Ubily>gradlew checkModules
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':checkModules'.
> java.lang.NullPointerException (no error message)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 693ms

To Reproduce

  1. Define multimodule Android project.
  2. Define Koin modules for each one.
  3. Make sure it works correctly.
  4. Apply next build.gradle file:
apply plugin: 'koin'

buildscript {
    ext.kotlin_version = '1.3.71'

    repositories {
        google ()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.koin:koin-gradle-plugin:2.1.5"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
  1. Write JUnit Test:
@Category(CheckModuleTest::class)
class KoinModulesTest : KoinTest {

    @Test
    fun checkAllModules() = checkModules {
        modules(koinModules) // there are all modules of the project
    }

}
  1. Then run command from Android Studio terminal:
    gradlew checkModules

Expected behavior
Correct work of the command "checkModules", without NPE.

Koin project used and used version (please complete the following information):

  •   org.koin:koin-gradle-plugin:2.1.5
    
  •   implementation "org.koin:koin-androidx-scope:2.1.5"
      implementation "org.koin:koin-androidx-viewmodel:2.1.5"
      testImplementation "org.koin:koin-test:2.1.5"
    
@arnaudgiuliani arnaudgiuliani added type:issue status:checking currently in analysis - discussion or need more detailed specs labels Apr 6, 2020
@kirich1409
Copy link
Contributor

For Android projects to proper check DI graph, you need to run the test using Robolectric or run it on an Android device

@Perfomer
Copy link
Author

Perfomer commented Apr 9, 2020

For Android projects to proper check DI graph, you need to run the test using Robolectric or run it on an Android device

Yeap, now it works without NPE & says that modules are checked. Thank you.

Although the guide remain incomplete.

I purposely remove one of my dependencies from the DI-graph, 'cause I want to see an error message about missing dependency. And... nothing. Test completed successfully.

So I don't understand what's the point of the Gradle script & tests.

@arnaudgiuliani
Copy link
Member

The Koin Gradle offers a checkModules task to run unit tests tagged with CheckModulesTest category. Unfortunately for Android projects, this task is not working (NPE like here). We need to hook on unitTestDebug Android Gradle task.

I've just done the fix for 2.1.6

@arnaudgiuliani arnaudgiuliani added status:accepted accepted to be developed and removed status:checking currently in analysis - discussion or need more detailed specs labels May 28, 2020
@arnaudgiuliani arnaudgiuliani added this to the 2.1.6 milestone May 28, 2020
@fmatosqg
Copy link

fmatosqg commented Aug 7, 2020

I'm running 2.1.6 but I still find errors in my module sample.
It happens with both targets checkModules and :sample:checkModules.

Could not determine the dependencies of task ':sample:checkModules'.
java.lang.NullPointerException (no error message)

Running with --info gives

Configure project :sample
Evaluating project ':sample' using build file 'some_folder_name/libs/bardeen/sample/build.gradle.kts'.
Creating configuration androidTestUtil
. . .
Selected primary task 'checkModules' from project :
Could not execute [class org.jetbrains.kotlin.gradle.plugin.statistics.DefaultKotlinBuildStatsService.buildFinished]

When I do ./gradlew connectedAndroidTest it still runs it and throws the same errors as I'd get from running from inside Android Studio, so I got that covered for me.

Maybe I need to wait for checkAndroidModules to land on 2.17?

@fmatosqg
Copy link

fmatosqg commented Aug 7, 2020

I think I found the reason, it may be because I have flavors on my sample module.

./gradlew checkAndroidModules
. . .
What went wrong:
Could not determine the dependencies of task ':sample:checkAndroidModules'.
Task with path 'testDebugUnitTest' not found in project ':sample'.

Sounds like a candidate for a separate issue, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:accepted accepted to be developed type:issue
Projects
None yet
Development

No branches or pull requests

4 participants