asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
285 stars 120 forks source link

gradle kotlin configuration :asciidoctor #678

Open vifeng opened 1 year ago

vifeng commented 1 year ago

Hi, I report my first issue, so thank you for your comprehension. Problem : I think it is the way that asciidoctor implemented their code that makes the users write the gradle configuration unnaturally. FYI, Gradle is now using kotlin as default instead of groovy. see below for detail code.

Error message when gradle clean build or gradle jar :

Could not determine the dependencies of task ':asciidoctor'.
> Configuration with name '<path>/spring-restdocs-asciidoctor-3.0.0.jar' not found.

Related code for build.gradle.kts

val asciidoctorExt by configurations.creating

dependencies {
    asciidoctorExt("org.springframework.restdocs:spring-restdocs-asciidoctor")
    }

tasks.asciidoctor {
    configurations(listOf(asciidoctorExt))
   // this line should in fact be written as such : configurations(asciidoctorExt) which doesn't build
}

see here, the message from Vampire from the gradle community for the reason of this syntax issue: that's imho a shortcoming of the Asciidoctor plugin that you should report. There is configurations(Object... configs) and configurations(Iterable configs) and it can handle either Configuration objects or anything else by converting it to a String and using that as configuration name. Configuration is iterable, so the second variant is chosen. The configuration is iterated and so the File instances are used. On those then toString() is called which gives the paths of the files in the configuration and that is then used as configuration name which gives the error you mentioned. Before you gave a String which is not Iterable, so the first variant was used and interpreted as configuration name correctly. So you either need to use configurations(asciidoctorExt as Any) or configurations(listOf(asciidoctorExt)) or configurations(asciidoctorExt.name). source

FYI link to a whole kotlin build file (following the best practices -as I can any way thanks to vampire help) can be found on my [github] (https://github.com/vifeng/TicketToTheMoon/commit/3564599aeee2ab77818ce68935dbd93306175731)