kotest-intellij-plugin icon indicating copy to clipboard operation
kotest-intellij-plugin copied to clipboard

Unable to run individual tests KMP tests

Open kirillzh opened this issue 2 years ago • 13 comments

When trying to run an individual KMP test in IJ/AS, getting this error:

Cannot locate tasks that match ':shared:money:impl:compileJava' as task 'compileJava' is ambiguous in project ':shared:money:impl'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac', 'compileDebugUnitTestJavaWithJavac', 'compileReleaseJavaWithJavac', 'compileReleaseUnitTestJavaWithJavac'.
Screenshot 2023-07-28 at 4 10 07 PM

kirillzh avatar Feb 18 '23 20:02 kirillzh

Can you provide a repro for this? It looks like a gradle error to me. The Kotest plugin never explicitly calls the compileJava task

Kantis avatar Mar 06 '23 21:03 Kantis

@Kantis, I see this happening when trying to run/debug individual tests from IDE. Seems to work fine with the whole test suite though: Screenshot 2023-03-10 at 6 04 51 PM

kirillzh avatar Mar 11 '23 02:03 kirillzh

I see this in modules that don't have JVM target (eg Android or iOS), without debugger as well. The only way that I was able to make unit tests run from IDE is by right clicking on a spec file and running from there: Screenshot 2023-04-18 at 10 25 12 PM

kirillzh avatar Apr 19 '23 02:04 kirillzh

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 18 '23 08:06 stale[bot]

@Kantis, I update the title and description of the ticket. The real issue that I'm seeing is that we are not able to run individual tests from IDE (clicking green arrow next to a test), whereas running the whole spec works (clicking green arrow next to a spec). Is there anything I can do to help debug this issue?

kirillzh avatar Jul 28 '23 23:07 kirillzh

I have the same problem. This should be reopened @kirillzh

Nek-12 avatar Aug 17 '23 09:08 Nek-12

@Kantis, do you have any pointers for how this issue could be resolved? Happy to attempt fixing this in the plugin itself but not sure where to look. Would appreciate your help here, thanks!

kirillzh avatar Sep 28 '23 10:09 kirillzh

The plugin does seem to generate the right configuration:

Screenshot 2023-09-28 at 7 48 47 PM

However when executing it for a KMP module it fails, here are the IDE logs:


2023-09-28 19:48:05,470 [2566302]   INFO - #com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker - About to execute Gradle tasks: [:shared:money:impl:compileJava, :shared:money:impl:testClasses]
2023-09-28 19:48:05,472 [2566304]   INFO - #o.j.p.g.GradleManager - Instructing gradle to use java from /Users/zhukov/Library/Java/JavaVirtualMachines/corretto-17.0.8.8.1.jdk/Contents/Home
2023-09-28 19:48:05,472 [2566304]   INFO - #com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker - Build command line options: [--continue, -Pandroid.injected.invoked.from.ide=true, -Pandroid.studio.version=231.9392.1.2311.10809438, -Pandroid.injected.attribution.file.location=/Users/zhukov/Development/wallet/app/.gradle]
2023-09-28 19:48:05,473 [2566305]   INFO - #o.j.p.g.s.e.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: --stacktrace --continue -Pandroid.injected.invoked.from.ide=true -Pandroid.studio.version=231.9392.1.2311.10809438 -Pandroid.injected.attribution.file.location=/Users/zhukov/Development/wallet/app/.gradle
2023-09-28 19:48:05,695 [2566527]   INFO - #com.android.tools.idea.gradle.project.build.invoker.GradleBuildInvoker - Gradle build failed in 222 ms

Gradle output error:

Cannot locate tasks that match ':shared:money:impl:compileJava' as task 'compileJava' is ambiguous in project ':shared:money:impl'. Candidates are: 'compileDebugAndroidTestJavaWithJavac', 'compileDebugJavaWithJavac', 'compileDebugUnitTestJavaWithJavac', 'compileReleaseJavaWithJavac', 'compileReleaseUnitTestJavaWithJavac'.

kirillzh avatar Sep 28 '23 10:09 kirillzh

The same issue here, just creating blank KMP project with Android and iOS targets (no JVM). and adding Kotest following official docs reproduces this. If I add JVM target - plugin works well.

OSemenovBoyarka avatar Nov 21 '23 10:11 OSemenovBoyarka

I've been debugging and prodding IntelliJ IDEA and the Android plugin's source code and found that there's actually a registry setting for IntelliJ IDEA. When you set the Registry... setting called android.task.runner.restricted to true (checking the box), it will make sure that Android task runner is only used for modules with the Android facet. Thanks to this it will correctly use the Gradle task runner and compile the underlying module correctly.

We still need to see if this can be enabled long-term and I'll be reaching out to JB to see if there's a reason not to use it and what's the plan for it. But being able to run Kotest from the gutter icons again is sweet!

TadeasKriz avatar Dec 08 '23 02:12 TadeasKriz

Thank you for figuring this out!

On Thu, 7 Dec 2023 at 20:37, Tadeas Kriz @.***> wrote:

I've been debugging and prodding IntelliJ IDEA and the Android plugin's source code and found that there's actually a registry setting for IntelliJ IDEA. When you set the Registry... setting called android.task.runner.restricted to true (checking the box), it will make sure that Android task runner is only used for modules with the Android facet. Thanks to this it will correctly use the Gradle task runner and compile the underlying module correctly.

We still need to see if this can be enabled long-term and I'll be reaching out to JB to see if there's a reason not to use it and what's the plan for it. But being able to run Kotest from the gutter icons again is sweet!

— Reply to this email directly, view it on GitHub https://github.com/kotest/kotest-intellij-plugin/issues/245#issuecomment-1846464053, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFVSGXMEVM2LBBVDTXY7O3YIJ4NNAVCNFSM6AAAAAAVARO3KCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWGQ3DIMBVGM . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sksamuel avatar Dec 08 '23 19:12 sksamuel

Any updates on this? I run into the same issue when running tests from IDE. Works fine when running via gradle. For us at the moment it would be quite painful to add jvm target to the modules as we do have a lot of modules.

mvarnagiris avatar Feb 07 '24 15:02 mvarnagiris

@TadeasKriz, correct me if I'm wrong but this is blocked by https://youtrack.jetbrains.com/issue/KT-65131/Incorrect-compilation-name-for-custom-test-runs-KotlinJvmTest-tasks-in-KMP-modules, right?

kirillzh avatar May 10 '24 05:05 kirillzh