Anyone has a working jacoco sample file?
# multiplatform
s
Anyone has a working jacoco sample file?
e
A task called "jacocoTestReport" is automatically created by the jacoco plugin, which you may want to consider modifying instead of creating a new one. It doesn't have a dependency on running the tests -- it's expected that you do that first though. If I recall correctly, there's some rationale as to why it shouldn't be a dependency (could be something that's tripping you up). Also double check the name of the .exec file that's generated. I have a working example here: https://github.com/erikc5000/island-time/blob/master/buildSrc/src/main/kotlin/multiplatform-library.gradle.kts
s
Thanks Erik! Finally managed to get it working. Do you know if it is possible to see the tested methods marked down with green/red bars within AS when using Jacoco? Or that functionality works only for IntelliJ code coverage?
e
Personally, I've only looked at the report in a web browser. Not sure if it works right in AS or not.
s
Ok thanks Erik 🙂
c
Following up on this thread, I was able to get this example working for a library multiplatform module after adding the
java-library
gradle plugin. The problem with this is that my app module which consumes the libraries fails to build. My workaround for now is a command line flag to turn coverage on and using a -x arg to prevent building the app module. But is there a less janky way to do this?
I noticed that Erik’s example uses a plugin for
published-library
but I can’t seem to find what that is.
e
That's a "precompiled script plugin". It's a Gradle script in buildSrc that can be applied to any project in the build to setup things or add tasks.
c
Ah, I see.
I actually ran into one other problem.
My tests aren’t able to find some of my classes, so a lot of them throw class not found exceptions.
Those exceptions were being masked by gradle caching, which is why they didn’t get noticed sooner.
So it seems like there’s an issue with running all the tests on the JVM and running common and jvm tests.
Is that working for you
?
e
That's usually caused by renamed classes that can still be found in the build directory. Deleting it will fix that.
c
At what point are you deleting it? For me, the issue reproduces consistently if I run ./gradlew clean before ./gradlew check
So after a lot of troubleshooting, it looks like my issue is being triggered by dependencies on other modules within my project. When enabling Jacoco, it looks like it loses track of multiplatform
project
dependencies (but is OK with non-project dependencies), and that is causing the exceptions when running the tests. Ideas on how I might resolve that?
No, I spoke too soon and that’s not actually it. Continuing to troubleshoot.
The actual culprit is inline methods. They are causing the java.lang.NoClassDefFoundError.