springfox / springfox-javadoc

Ability to use Javadoc for documentation for generating OpenAPI specifications
Apache License 2.0
17 stars 15 forks source link

Using with gradle #8

Open laxika opened 6 years ago

laxika commented 6 years ago

Hello guys,

Can I use this plugin with Gradle? If yes then how?

Thanks!

rahuljain1804 commented 6 years ago

+1

anesterkina commented 6 years ago

Hi guys,

There's an issue with gradle. The default javadoc task always sets the -d option (output directory for the standard javadoc doclet). However, the custom springfox-javadoc doclet does not recognize that option and instead uses the -classdir option to set the output directory. So your task will always pass the -d option to the custom doclet, but the doclet won't work because of the unrecognized option.

A managed to write a task whith a workaround that works whith gradle 3.3, but it results in error in gradle 4.8.

task javadoc2swagger(type: Javadoc , dependsOn: compileJava ) {
    source = sourceSets.main.allJava
    classpath = sourceSets.main.compileClasspath
    options.doclet = "springfox.javadoc.doclet.SwaggerPropertiesDoclet"
    options.addStringOption("classdir", "${sourceSets.main.output.resourcesDir}")
    options.addStringOption("exceptionRef", "true")
    options.encoding("UTF8")

    //workaround not to pass default options
    title = null
    options.addStringOption("d", null)

    doFirst {
        options.docletpath = configurations.springfoxJavadoc.files.asList()
    }
}

jar.dependsOn(javadoc2swagger)

For newer versions of gradle I guess you'll need to use an ant task to get the doclet to work.

To get the doclet to work properly with newer versions of gradle, it would be better to use the -d option instead of -classdir or at least to recognize the -d option and simply ignore it.

dilipkrish commented 6 years ago

Thanks for the hint @AnnaNesterkina. Ill try to update the readme with instructions.

anesterkina commented 6 years ago

@dilipkrish as I mentioned, this code doesn't work with newer versions of gradle. What do you think about making it possible to pass the output dir via -d option (it's set via destinationDir in gradle and destDir in maven). Spring Auto Rest Docs does so, you can view their documentation ( https://htmlpreview.github.io/?https://github.com/ScaCap/spring-auto-restdocs/blob/v2.0.1/docs/index.html ). We can leave the classDir option for backwards compatibility. I am willing to submit a pull request for this.

rahuljain1804 commented 6 years ago

@AnnaNesterkina, @dilipkrish - I also made changes for the same. I think we should just created a PR and release a new version for the same. If you can give me permissions to create a PR, I can submit that

dilipkrish commented 6 years ago

@AnnaNesterkina @rahuljain1804 would be great if either of you have a fix in mind for this.

rahuljain1804 commented 5 years ago

@dilipkrish - Missed the notification. Saw this just now. I guess there is already one PR open for the issue which should fix it (however, it is not backward compatible). For now, I was using it by adding additional parameters for the newer versions of gradle. Let me know if that works. I can submit a PR for the same.

dilipkrish commented 5 years ago

@rahuljain1804 thank for helping out, will definitely reach out if I have questions