How to add Jacoco plugin to TOML version catalog f...
# gradle
h
How to add Jacoco plugin to TOML version catalog file Instead of
id("jacoco")
in the plugins section of build.gradle I would like to use
alias(libs.plugins.jacoco)
e
for the record,
id("foo")
is actually
id("org.gradle.foo")
when dealing with built-in plugins
c
Not sure if this is the same in this case, but when applying convention plugins from the version catalog, the version you should use is
unspecified
h
I have a Kotln project and was using jacoco without needing to specify a version for it. I'll try what you suggested above see if that works. I'll try
unspecified
as well.
Copy code
org.gradle.api.GradleException: Error resolving plugin [id: 'org.gradle.jacoco', version: 'unspecified']
c
Because it's a gradle built-in plugin, you don't have to specify a version in the
plugins
block. However, it's mandatory to always specify a version in the version catalog, even if it's a built-in plugin.
unspecified
works for convention plugins, I don't know if it works for built-in plugins
h
Well it was worth trying but it doesn't work I put it like this in the toml file.
Copy code
jacoco = { id = "org.gradle.jacoco", version = "unspecified"}
should I use verseion.ref ?
e
if you want type-safety, all the built-in plugins have generated accessors, so
Copy code
plugins {
    jacoco
}
just works in the Kotlin DSL
h
Okay so some plugins could be loaded from version catalogs and other just directly defined in my kotlin DSL gradle file.
c
Yes
e
if the plugin name contains non-identifier characters, you may need to use backticks, e.g.
Copy code
plugins {
    `kotlin-dsl`
}
(you could write ``jacoco`` too but there's no need to)
h
Meaning I don't need to alias for kotlin?
Copy code
[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinVersion" }
and then just
Copy code
plugins {
    `kotlin`
}
like this or whithout the backticks? Instead of
Copy code
plugins {
   alias(libs.plugins.kotlin)
}
e
no, Kotlin is not a built-in plugin
Gradle does have
kotlin-dsl
and
embedded-kotlin
built-in, but those are different than
org.jetbrains.kotlin.*
h
I'm using a spring boot project and transforming it to version catalog. I'm not sure what the kotlin-dsl plugin is for.
e
for writing your own Gradle plugins
h
Oh okay it's nice to see that I do get syntax completion in the plugin section..
e
I was just giving an example. there's lots of other built-in Gradle plugins with dashes in their names, e.g.
java-library
h
Yes saw that and Intellij is giving syntax completion and adding those backticks to it for me.
v
unspecified
is an actual version. If you have to use
unspecified
for your convention plugins @CLOVIS, then just because that is the version you configured in the build for those convention plugins. In this case "configured" by not configuring explicitly, but keeping the default value which is "unspecified" but otherwise not a magic string, but a version like any other. đŸ˜‰
c
I can't decide if that's better or worse
v
đŸ¤·
Actually, the version you put there is probably meaningless if the convention plugin is coming from an included build or
buildSrc
. Because things from included builds usually take precedence over declared versions, so you could also use
_
as version or any other String you like.
c
Nope, it's not… I tried to put stuff like
1.0
and it doesn't work. Only
unspecified
is accepted.
v
When it comes from an included build? I just tried and it works perfectly fine.
1169 Views