Generate Javadoc Jar

Hello, World!

How would I go about making a project generate javadocs with a .jar output? With maven all I need to do is add the maven-javadoc-plugin and run “mvn javadoc:jar” and it is placed in the target/ folder.

What is the equivalent in Maven Gradle?


FTFY :wink:

Are you asking which task to run to generate javadoc?

Whenever I run the javadoc task or any of the publishXXX tasks (when the maven-publish plugin is applied), the docs are always bundled in a .jar file.

I think assemble generates javadoc too.

I don’t know much about Gradle so I’m unsure what exactly you’re talking about. On the command line when I run “gradle javadoc” it generates all of the documentation in .html, .js, and .css form in the directory: project_name/subproject_name/build/docs/javadoc/.

What it does not include is the .jar version of that same documentation. How do I make it so it does that? If it makes a difference, the project has subprojects that need to have their documentation generated.

Sorry my mistake. You’re right. javadoc on its own only produces the actual html.

Have you tried applying the 'maven-publish` plugin?

    id 'maven-publish'
group = 'com.example'
version = '0.0.0'
task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    classifier = 'sources'

task javadocJar(type: Jar) {
    from javadoc
    classifier = 'javadoc'
publishing {
    publications {
        mavenJava(MavenPublication) {           
            artifactId = 'ziluckmichael'
            artifact sourcesJar
            artifact javadocJar
    repositories {
        maven {
            url 'repo'

…then gradle publish will get you your code, javadoc and sources jars in a repo directory as specified in the repositories{} stanza.

If you only want the javadoc, try removing the artifact sourcesJar and from I’ve never run that task without all three of them myself though. But it might work.

Thinking about the script I just posted above, I believe you can just run the javadocJar task on its own if you only want the javadoc and not the other two jars.

That will get you a jar in your project’s build/libs/ folder.

The docs explain it all better than I ever could.

I went to go do this same thing again and Googled my problem and here I am!

For the more recent versions of Gradle, should I instead do this:
archiveClassifier.set("javadoc") rather than this: classifier = "javadoc"?

According to this

…and this, I believe you’ve absolutley nailed it, @ziluckmichael.

Although @ljacomet mentions „the Kotlin DSL“, it’s the same method in the Groovy DSL. I assume by him saying „DSL sugar“, that he’s also implying that it would be possible in the Groovy DSL to also do archiveClassifier = 'javadoc'.

Now then. Can you help me out on that request for functionality review. You know? I scratch your back? You scratch mine? :wink: