如何在gradle构建中生成Enunciate文档

时间:2014-09-24 23:21:52

标签: gradle enunciate

Enunciate目前没有gradle插件(https://jira.codehaus.org/browse/ENUNCIATE-815)。有没有办法从Gradle手动触发文档的构建?

1 个答案:

答案 0 :(得分:1)

我发现我需要提供各种JAX-RS JAR文件,以便在从命令行运行它时发挥作用。使用Gradle中的configurations.runtime.asPath属性非常简单,该属性传递了我在构建项目时已解决的所有RESTEasy工件。

import org.apache.tools.ant.taskdefs.condition.Os

task enunciate(type:Exec) {
  if (Os.isFamily(Os.FAMILY_WINDOWS)) {
      //on windows:
      commandLine 'cmd', '/c', 
      'enunciate-1.29\\bin\\enunciate.bat  -Edocs docs -f enunciate.xml -cp "' + configurations.runtime.asPath + 
      '" src/com/company/rest/RestApi.java'
  } else {
      //on linux
      commandLine './enunciate-1.29/bin/enunciate -Edocs docs -f enunciate.xml -cp "' + configurations.runtime.asPath + 
      " src/com/company/rest/RestApi.java'
  }

  //store the output instead of printing to the console:
  standardOutput = new ByteArrayOutputStream()

  //extension method stopTomcat.output() can be used to obtain the output:
  ext.output = {
    return standardOutput.toString()
  }
}