springfox-javadoc icon indicating copy to clipboard operation
springfox-javadoc copied to clipboard

Using with gradle

Open laxika opened this issue 7 years ago • 8 comments

Hello guys,

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

Thanks!

laxika avatar May 28 '18 09:05 laxika

+1

rahuljain1804 avatar Jun 27 '18 14:06 rahuljain1804

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.

anesterkina avatar Jun 28 '18 09:06 anesterkina

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

dilipkrish avatar Jun 28 '18 12:06 dilipkrish

@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.

anesterkina avatar Jun 29 '18 07:06 anesterkina

@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

rahuljain1804 avatar Jun 29 '18 08:06 rahuljain1804

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

dilipkrish avatar Aug 12 '18 16:08 dilipkrish

@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.

rahuljain1804 avatar Sep 26 '18 10:09 rahuljain1804

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

dilipkrish avatar Nov 09 '18 12:11 dilipkrish