Sorry for negative question :stuck_out_tongue: But...
# gradle
j
Sorry for negative question 😛 But I again and again have wasted a lot of hours trying to configure Gradle to do (in my mind) basic stuff. I have a Kotlin jvm Project using Kotlin Gradle Script. I would love to have tests configured and report standard xml information about success/failures/ignored and get testcoverage, which then I can pass on to my CI environment. Does anyone know if there exists a straight forward solution to this? I'm fully fine with replacing everything that I currently have with jacoco with something else if that's the prefered way of doing things.
v
Actually sounds to me like pretty standard things that should work without much configuration. What is it that you have to extensively configure?
j
This is my current setup, but this does not report test coverage.
v
Ok, besides that the
java {}
block should better be outside the
tasks
block as it is just a bit misleading having it in there, I don't see tooo much configuration, or actually too much you really need. Kotlin Gradle plugin with 1.5.30 adds Java Toolchain support, so the three jvmTarget settings probably can be replaced with one setting (https://youtrack.jetbrains.com/issue/KT-43095) Explicitly specifying the
junit-jupiter
engine is not necessary, except if you have multiple JUnit Platform Engines on the class path and want to restrict to only use that one engine, but then why having the other engines on the class path. The
testLogging
and
maxHeapSize
settings, well, if you are not happy with the defaults, you need to adjust it, but you can also refactor it into some opinionated convention plugin that you then apply in your builds. But actually also there you have redundant settings. For example
exceptionFormat = FULL
is the default setting. Or manually configuring
STANDARD_ERROR
and
STANDARD_OUT
events is the same as doing
showStandardStreams = true
. Generally said, Gradle loves convention-over-configuration. It provides sane defaults for most things and if you are happy with them, you don't need much configuration. But at the same time it is flexible enough to adjust the build to your needs but that you can also factor out into some plugin that you can then cleanly apply to all your projects where you want that configuration.
😍 1
j
Thanks for the in-depth information. I have updated it to this now. I love less config 🙂
only issue I have left, is how do I get test coverage reported into a xml file?
by looking at the gitlab-ci docs, it seems it should be reported into the directory
build/jacoco/jacoco.xml
v
Copy code
plugins {
    jacoco
}
tasks.jacocoTestReport {
    reports {
        html.required.set(false)
        xml.required.set(true)
    }
}
iirc
👍 1
j
And then I will run
gradlew test jacocoTestReport
. Now I got the file
👌 1