2015-12-16 74 views
1

我遵循Spring Rest Docs參考文檔中關於構建配置的說明。但「片段」屬性不會出現暴露於Asciidoctor當我嘗試做從gradle中找不到asciidoctor的「片段」屬性

include::{snippets}/.... 

,但我得到一個asciidoctor「警告:含有下探缺少屬性參考線:片段」

如果我刪除屬性引用並直接放入路徑中,出現包含文件的內容。

這裏是包含休息文檔/ Asciidoctor信息的文件的build.gradle:

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(':...') 
    } 
} 

感謝。

+1

您是否想要將Asciidoctor插件應用於外部項目並進行配置?我想知道是否該屬性沒有被設置,因爲'build/generated-snippets'文件夾不存在相對於該項目。如果不是這樣,使用'--debug'運行構建會顯示正在運行的'asciidoctor'命令。你能用調試輸出的相關部分更新問題嗎? –

+0

我最初在項目build.gradle中擁有所有與asciidoctor相關的條目,但它仍然無效,所以我將它移到了父項目中。我使用--debug運行了構建版,並沒有看到來自asciidoctor的任何命令 - 只是顯示它找到了jar文件和版本以及它從maven存儲庫獲得的命令行。我也沒有發現任何「片段」的提及,以防萬一在這方面產生任何事情。我還將'testCompile'移動到項目gradle文件中(受影響的測試在父項級別時在項目中運行)。 – Les

+0

你跑了什麼命令? './gradlew asciidoctor --debug'應該可以做到。 –

回答

1

您可以將名爲snippets的屬性添加到指向snippetsDir路徑的api-guide.adoc中。

:snippets: ../../../build/generated-snippets