Is there any best practises to share jacoco config...
# gradle
j
Is there any best practises to share jacoco configuration between subprojects via kotlin gradle script?
h
Don't know what config you mean exactly, but either a helper function in buildSrc project or a precompiled script plugin in buildSrc should be the right thing for the job
j
I have a precompiled plugin but I am applying it to the root.
First I was not merging all reports, but later I changed it to merge all so I can easily upload it to tools like codacy
j
@Hanno Would you have a function in
buildSrc/build.gradle.kts
, or where would you put this configuration?
h
No that wouldnt work, as code in buildSrc/build.gradle.kts is only available in this very file i think. You can just add a jacocoHelpers.kt in buildSrc/src/main/kotlin, as if it's a regular project. And use it afterwards in the whole build
j
I have only managed to create objects within the buildSrc/.../*.kt which I then can use as variables. But would it be possible to have a function which would do something like this in gradle?
Copy code
fun setupJacoco() {
  // Gradle code below
  jacoco {
    toolVersion = "0.8.4"
    reportsDir = file("$buildDir/reports")
  }
}
h
You would need to put the plugin dependency of for example jacoco into buildSrc as a imementation dependency, so that you can compile against. Afterwards, you can apply the jacoco plugin in your projects without specifying the version
With that, yes, you can do sth like that :)
Maybe the precompiled script stuff is better for your use case though
j
not sure what is the best approach. But my issue is I have a multi module project, and I have jacoco configuration with about 100 lines. Having 100 lines exactly the same in two different build.gradle.kts files within the same git repository, seems so wrong and I want to find what is the best way of structuring this.
j
precompiled plugin
so you can do in each module something like
Copy code
plugins {
    my-jacoco-config-plugin
}
j
having a precompiled plugin, would that be possible within the same git repository, or would you recommend to separate it?
j
or even do something like allprojects { apply<MyJacocoConfigPlugin>() }
😍 1
j
same git repo = one intellij project *
j
you can create the precompiled plugin in buildSrc
and use it in all your subprojects or in the root build.gradle.kts
j
Perfect. thanks. I guess I would find good guides by searching on google for "kotlin gradle scipr precompiled plugin"
message has been deleted
I give up for today, will try again later
v
That would not be a property of the tool that is used, but of the user of the tool, you can abuse any tool instead of just reading its documentation. 😉
109 Views