task("pdfJar") creates an eager (not using task configuration avoidance) instance of an ad-hoc task named pdfJar. You then give this task of type DefaultTask to the sign method and so it of course is not an archive task.
If you swap it around to
tasks.create("pdfJar", Jar::class) { ... }
signing {
sign(task("pdfJar"))
}
you will thus get an error, that you try to add another task with the name pdfJar.
What you want instead is to give your already created task to the sign method, so this:
val pdfJar = tasks.create("pdfJar", Jar::class) { ... }
signing {
sign(pdfJar)
}
Now if you consider task-configuration avoidance, you want to use register instead of create and then need to use the closure variant of sign to not trigger task realization early as it does not accept a TaskProvider:
val pdfJar = tasks.register("pdfJar", Jar::class) { ... }
signing {
sign(closureOf<SignOperation> { sign(pdfJar.get()) })
}
And finally we can use property delegation to make it a bit nicer:
val pdfJar by tasks.registering(Jar::class) { ... }
signing {
sign(closureOf<SignOperation> { sign(pdfJar.get()) })
}