Search code examples
gradleenunciate

How can I generate Enunciate documentation in a gradle build


Enunciate currently does not have a gradle plugin (https://jira.codehaus.org/browse/ENUNCIATE-815). Is there any way to trigger a build of the docs from Gradle manually?


Solution

  • I found that I needed to supply the various JAX-RS JAR files to enunicate when running it from the command line. This was quite trivial using the configurations.runtime.asPath property in Gradle, which passed through all the RESTEasy artefacts I was already resolving when building the project.

    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()
      }
    }