Gradle script kotlin: how to configure asciidoctor plugin?

I would like to configure the asciidoctor pluign in gradle script kotlin (build.gradle.kts) to use spring rest docs. I read this https://github.com/gradle/gradle-script-kotlin/blob/master/doc/getting-started/Configuring-Plugins.md but this did not work for the asciidoctor plugin.

I tried the following two things and both of them complain with ‘Unresolved Reference: AsciidocotorTask’

1. configure<org.asciidoctor.gradle.AsciidoctorTask> { }

2. val asciidoctor = tasks.getByName("asciidoctor") as org.asciidoctor.gradle.AsciidoctorTask

Thanks for any help
Below you find my complete build.gradle.kts file content:

import org.gradle.script.lang.kotlin.extra

buildscript {
val springBootVersion: String = "1.5.2.RELEASE"
val kotlinVersion: String = "1.1.1"

extra["kotlinVersion"] = kotlinVersion
extra["springBootVersion"] = springBootVersion

repositories {
    gradleScriptKotlin()
    mavenCentral()
}

dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
    classpath("org.asciidoctor:asciidoctor-gradle-plugin:1.5.3")
}

}

apply {
  plugin("kotlin")
  plugin("kotlin-spring")
  plugin("org.springframework.boot")
  plugin("org.asciidoctor.convert")
}

configure<JavaPluginConvention> {
  setSourceCompatibility(1.8)
  setTargetCompatibility(1.8)
}


repositories {
 gradleScriptKotlin()
}

val springBootVerison = extra["springBootVersion"] as String
val kotlinVersion = extra["kotlinVersion"] as String

dependencies {
 compile("org.springframework.boot:spring-boot-starter-web:$springBootVerison") 
 compile(kotlinModule("stdlib", "1.1.1"))
 compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.8.7")
 compile("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
 compile("org.springframework.restdocs:spring-restdocs-mockmvc:1.1.2.RELEASE")
 testCompile("org.springframework.boot:spring-boot-starter-test")
}

//Unresovled Reference: AsciidocotorTask
configure<org.asciidoctor.gradle.AsciidoctorTask> {
// do stuff
}

//Unresovled Reference: AsciidocotorTask
val asciidoctor = tasks.getByName("asciidoctor") as org.asciidoctor.gradle.AsciidoctorTask

I have been struggling with this as well, but I don’t think I’ve gotten as far as you have.

I did some work and got it to work for pdf and html docs, though some of the things I tried didn’t work. I couldn’t figure out how to

‘’‘’
sources {
include(“file”)
}
‘’‘’

here’s your modified file that works for me:

import org.gradle.script.lang.kotlin.extra
import org.asciidoctor.gradle.AsciidoctorPlugin
import org.asciidoctor.gradle.AsciidoctorTask

buildscript {
val springBootVersion: String = “1.5.2.RELEASE”
val kotlinVersion: String = “1.1.1”

extra["kotlinVersion"] = kotlinVersion
extra["springBootVersion"] = springBootVersion
repositories {
    gradleScriptKotlin()
    mavenCentral()
}
dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
    classpath("org.asciidoctor:asciidoctor-gradle-plugin:1.5.3")
    classpath("org.asciidoctor:asciidoctorj-epub3:1.5.0-alpha.6")
    classpath("org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11")
}

}

apply {
plugin(“kotlin”)
plugin(“kotlin-spring”)
plugin(“org.springframework.boot”)
plugin(“org.asciidoctor.convert”)
plugin()
}

configure {
setSourceCompatibility(1.8)
setTargetCompatibility(1.8)
}

repositories {
gradleScriptKotlin()
}

val springBootVerison = extra[“springBootVersion”] as String
val kotlinVersion = extra[“kotlinVersion”] as String

dependencies {
compile(“org.springframework.boot:spring-boot-starter-web:$springBootVerison”)
compile(kotlinModule(“stdlib”, “1.1.1”))
compile(“com.fasterxml.jackson.module:jackson-module-kotlin:2.8.7”)
compile(“org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion”)
compile(“org.springframework.restdocs:spring-restdocs-mockmvc:1.1.2.RELEASE”)
testCompile(“org.springframework.boot:spring-boot-starter-test”)
}

task(“ascii”) {
//val types = HashSet()
//types.add(“pdf”)
//types.add(“html”)
//backends = types

//backends = mutableSetOf("html", "pdf")
//backend = "pdf"
backends("pdf", "html")
sourceDir = file(".")

// sources {
// include(“backwoods.adoc”)
// exclude(“camping.adoc”)
// }
}

I had trouble with epub3, I think it didn’t like some of my files.

I don’t know how to get nice stylesheets for my docs, though.