Configure Gradle to publish sources and javadoc

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

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

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 05:08

    2017, Gradle 4.0 Edition:

    apply plugin: 'maven'
    apply plugin: 'maven-publish'
    
    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
    
                artifact sourceJar
                artifact packageJavadoc
            }
        }
    }
    
    javadoc {
      source = sourceSets.main.allJava
      classpath = configurations.compileClasspath
    
      options
      {
        setMemberLevel JavadocMemberLevel.PUBLIC
        setAuthor true
    
        links "https://docs.oracle.com/javase/8/docs/api/"
      }
    }
    
    task sourceJar(type: Jar) {
      classifier = 'sources'
      from sourceSets.main.allJava
    }
    
    task packageJavadoc(type: Jar) {
        from javadoc
        classifier = 'javadoc'
    }
    

    Works with gradle publish and gradle publishToMavenLocal

提交回复
热议问题