发布Android开源库到JitPack.io附带文档和源码

/library/build.gradle 中添加:

// for publishing to JitPack.io with sources and javadoc

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}

task javadoc(type: Javadoc) {
    failOnError  false
    source = android.sourceSets.main.java.sourceFiles
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    classpath += configurations.compile
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

这样在使用这个开源库时可以方便的查看文档和源码。像这样:

发布Android开源库到JitPack.io附带文档和源码_第1张图片
查看文档

参考

https://github.com/GcsSloop/AndroidNote/blob/master/Course/jitpack-javadoc.md

你可能感兴趣的:(发布Android开源库到JitPack.io附带文档和源码)