Configure Gradle to publish sources and javadoc

后端 未结 4 556
南方客
南方客 2021-02-05 04:55

How do I configure Gradle to publish sources and javadoc jars to a repository?

4条回答
  •  一个人的身影
    2021-02-05 05:14

    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

提交回复
热议问题