I want to generate my JavaDocs into a given directory in my project root, I know that the destinationDir
property exists, but how do I use it also given that my build.gradle
exists within a directory inside of my project root. I provided a small diagram below:
/projectRoot
/lib
/build/docs/javaDocs <--- JavaDocs here by default
build.gradle
/docs <---- Need JavaDocs here
Taking a look at the documentation for JavaDocs in gradle, here. I knew that the destinationDir property existed so I attempted to set it like the provided example. This didn't have the intended affect and instead generated nothing, or is it going something outside of my project directory?
tasks.withType(Javadoc).configureEach {
exclude ('com/nest/egg/**')
options.addStringOption("charset", "utf-8")
options.addStringOption("docencoding", "utf-8")
options.addStringOption("encoding", "utf-8")
destinationDir = reporting.file("docs") // Also tried "/docs", "docs/"
}
You need to pass a Java File
object to destinationDir
specifying your desired location1. So you can write:
destinationDir = layout.projectDirectory.dir("..").dir("docs").asFile
Here you are using Gradle's ProjectLayout
object. Each dir()
call gives you a Gradle Directory
so you must finally call asFile
to finally get the Java File
object that you need.
1I am not sure what object you are using when you call reporting.file("docs")
but the ProjectLayout
object gives you all you need.