4

I'm following the directions in the Spring Rest Docs reference doc with regards to the build configuration. But the 'snippets' attribute doesn't appear to be exposed to Asciidoctor when I try to do

include::{snippets}/....

but I get an asciidoctor "warning: dropping line containing reference to missing attribute: snippets"

If I remove the attribute reference and put in the path directly, the contents of the included file appear.

Here is the build.gradle file containing the Rest Docs/Asciidoctor info:

buildscript {
    ext {
        springBootVersion = '1.3.0.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

plugins {
    id "org.asciidoctor.convert" version "1.5.3"
}


allprojects {
    apply plugin: 'groovy'
    apply plugin: 'idea'

    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    group = 'com....'

    ext {
        si = [version: '4.1.7.RELEASE']
        groovy = [version: '2.4.5']
        newRelic = [version: '3.13.0']
        jackson = [version: '2.6.2']
    }

    repositories {
        mavenCentral()
        maven {
            url "http://artifacts...."
        }
        maven {
            url "http://artifacts..../public-snapshots/"
        }
    }

    sourceSets {
        main {
            groovy {
                srcDirs = ['src/main/groovy']
            }
        }
    }

    test {
        include "**/*Test.*"
        exclude "**/*TestBase.*"
        exclude "**/*IntegrationTest.*"
    }

    configurations {
        all*.exclude group: 'org.eclipse.persistence'
        all*.exclude group: 'org.codehaus.jackson'
        all*.exclude group: 'org.slf4j', module: 'log4j-over-slf4j'
        all*.exclude group: 'log4j'
    }

    dependencies {
        compile "org.codehaus.groovy:groovy-all:${groovy.version}"
        compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:${jackson.version}"
        compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jackson.version}"
        compile 'org.mockito:mockito-core:+'
        testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.0.1.RELEASE'
    }

    task wrapper(type: Wrapper) {
        gradleVersion = '2.9'
    }
}

ext {
    snippetsDir = file('build/generated-snippets')
}

test {
    outputs.dir snippetsDir
}

asciidoctor {
    attributes 'snippets': snippetsDir
    inputs.dir snippetsDir
    dependsOn test
}

project(':...') {
    dependencies {
        compile project(':...')
    }
}

Thanks.

Les
  • 487
  • 1
  • 10
  • 22
  • 1
    Did you mean for the Asciidoctor plugin to be applied and configured on the outer project? I wonder if the attribute's not being set because the `build/generated-snippets` folder doesn't exist relative to that project. If that's not it, running the build with `--debug` will show you the `asciidoctor` command that's being run. Can you update the question with the relevant portion of the debug output? – Andy Wilkinson Dec 17 '15 at 10:24
  • I originally had all of the asciidoctor-related entries in a project build.gradle and it still didn't work, so I moved it to the parent. I ran the build with --debug and didn't see any commands from asciidoctor - just lines showing that it found the jar file and the version and that it got if from the maven repository. I also didn't find any reference to 'snippets', just in case anything was generated in that regard. I've also moved the 'testCompile' into the project gradle file (affected tests being run in the project when it was at the parent level). – Les Dec 17 '15 at 17:46
  • What command did you run? `./gradlew asciidoctor --debug` should do the trick. – Andy Wilkinson Dec 18 '15 at 12:35

1 Answers1

6

You can add an attribute named snippets into the api-guide.adoc, which points to the path of snippetsDir.

:snippets: ../../../build/generated-snippets
xiaofeig
  • 131
  • 1
  • 4