Configure Gradle to publish sources and javadoc

Solution as of Gradle 6.0

Here’s the somewhat minimal configuration you can use if you’re on Gradle 6.0 or later; note the newly introduced withSourcesJar() and withJavadocJar() methods:

plugins {
    id 'java'
    id 'maven-publish'
}

group = 'com.example'

java {
    withSourcesJar()
    withJavadocJar()
}

publishing {
    repositories {
        maven {
            url="file:///tmp/my-repo"
        }
    }
    publications {
        myJava(MavenPublication) {
           from components.java
       }
    }
}

Of course, you can also use the ivy-publish plugin instead of maven-publish.

See also the Gradle docs:

  • on the two new methods
  • on the maven-publish plugin
  • on the ivy-publish plugin

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)