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

Unable to run individual tests KMP tests #245

Open
kirillzh opened this issue Feb 18, 2023 · 13 comments
Open

Unable to run individual tests KMP tests #245

kirillzh opened this issue Feb 18, 2023 · 13 comments

Comments

@kirillzh
Copy link

kirillzh commented Feb 18, 2023

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
@Kantis
Copy link
Member

Kantis commented Mar 6, 2023

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

@kirillzh
Copy link
Author

@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
Copy link
Author

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

@stale
Copy link

stale bot commented Jun 18, 2023

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 stale bot added the wontfix This will not be worked on label Jun 18, 2023
@kirillzh kirillzh changed the title Trying to debug jvm test throws Task 'compileJava' not found in project Unable to run individual tests Jul 28, 2023
@stale stale bot removed the wontfix This will not be worked on label Jul 28, 2023
@kirillzh kirillzh changed the title Unable to run individual tests Unable to run individual tests KMP tests Jul 28, 2023
@kirillzh
Copy link
Author

@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?

@Nek-12
Copy link

Nek-12 commented Aug 17, 2023

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

@kirillzh
Copy link
Author

@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
Copy link
Author

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'.

@OSemenovBoyarka
Copy link

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.

@TadeasKriz
Copy link

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!

@sksamuel
Copy link
Member

sksamuel commented Dec 8, 2023 via email

@mvarnagiris
Copy link

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.

@kirillzh
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants