If I put my custom task into a build-logic composi...
# community-support
b
If I put my custom task into a build-logic composite build folder, what kind of build.gradle.kts do I need? Do I need
Copy code
plugins {
    `kotlin-dsl`
}
or something else entirely? What do I need to add in the build.gradle.kts file that makes use of that task?
1
v
That's a way too generic question actually. If you for example write your task in Java,
kotlin-dsl
would work, but would apply way too many unnecessary things. If you anyway also use precompiled Kotlin DSL script plugins, then
kotlin-dsl
is anyway what you need so it would be fine. ... And about where you use it, also depends, if you only have a task type, you either need to add a dependency in the
buildscript { ... }
block, or you can add a no-op plugin alongside your task and then apply that plugin in your build script just to get the classes onto the buildscript classpath.
b
thanks, I'm migrating custom Kotlin tasks from buildSrc right now
v
Well, you can do use
kotlin-dsl
, or you can use plain
K/JVM
plugin, but if you do the latter, you also need to be aware that the sam-with-receiver plugin and the assignment plugin are not configured unless you do it yourself and so on. If you did not have a build script in
buildSrc
, then applying
kotlin-dsl
should be the closest match afair. If you do have a build script in
buildSrc
, you probably need the same or similar in your
build-logic
.
b
I do need to create an artifact version and group for the build-logic folder, correct?
and then add something like this in the build.gradle.kts where I want to make use of the task
Copy code
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("<http://com.my:task:1.0.0|com.my:task:1.0.0>")
    }
}
b
yeah, that was it
I was reading through that section and missed a section about just including tasks
plugins and convention plugins are described, as are dependencies for normal code
v
I do need to create an artifact version and group for the build-logic folder, correct?
Actually, no. If it is coming from an included build, the version you declare is ignored anyway, so you can leave it out. And if you don't define a group, it is empty. So you can depend on
":build-logic"
which will work, as it has an empty group and no version. In that form it just looks like a project dependency but is actually a GAV dependency.
and then add something like this in the build.gradle.kts where I want to make use of the task
If you don't have some plugin you also apply, or added it to a higher classpath already, then yes.
b
oh, thank you