Upgrading asciidoctor.convert to asciidoctor.jvm.convert

Viewed 699

I am trying to upgrade asciidoctor since the old one is not supported anymore in gradle version 7. The problem is that I am not sure how to upgrade it from my current gradle kotlin code. (I only found some example with groovy). The gradle code I have currently looks a bit like the following:

plugins {
    id("org.asciidoctor.convert") version "2.4.0"
    ....
    kotlin("jvm") version "1.5.0"
    kotlin("plugin.spring") version "1.5.0"
}

....

repositories {
    mavenCentral()
    maven { url = uri("https://repo.spring.io/milestone") }
    maven { url = uri("https://repo.spring.io/snapshot") }
    jcenter()
}

dependencies {
    ....

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

val snippetsDir by extra { file("build/generated-snippets") }
tasks.test {
    useJUnitPlatform()
    outputs.dir(snippetsDir)

    mustRunAfter(tasks.flywayMigrate.get())
}

tasks.asciidoctor {
    dependsOn(tasks.test.get())
    sourceDir("src/main/docs")
    inputs.dir(snippetsDir)
    attributes["snippets"] = file(snippetsDir)
    attributes["docinfo1"] = ""
    attributes["environment-${project.properties["spring.profiles.active"]}"] = true
}

With the following errors when I change org.asciidoctor.convert to org.asciidoctor.jvm.convert:

Expression 'asciidoctor' cannot be invoked as a function. The function 'invoke()' is not found

And:

Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public val TaskContainer.asciidoctor: TaskProvider<AsciidoctorTask> defined in org.gradle.kotlin.dsl

The example that I found online looks like:

configurations {
    asciidoctorExt
}

dependencies {
    asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
    // …
}

asciidoctor {
    configurations 'asciidoctorExt'
    // …
}

Could someone maybe explain what I have to change so I can upgrade my asciidoctor version.

1 Answers

The way I got this to work is:

plugins {
    id("org.asciidoctor.jvm.convert") version "2.4.0"
}

val asciidoctorExt by configurations.creating

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

val snippetsDir by extra { file("${buildDir}/generated-snippets") }

val test = tasks.named<Test>("test") {
    outputs.dir(snippetsDir)
}

tasks.named<org.asciidoctor.gradle.jvm.AsciidoctorTask>("asciidoctor") {
    dependsOn(test)
    inputs.dir(snippetsDir)

    configurations("asciidoctorExt")

    setSourceDir("src/doc/asciidoc")
}
Related