即使一般的gradle腳本也可以JitPack也可以打包出插件的梅忌,只是打包的插件是沒有源碼和文檔的,對于引用是查看源碼明顯不方便时迫,所以最好修改下打包腳本净刮,生成源碼和文檔以便閱讀。
關(guān)于JitPack
JitPack可以很方便的將GitHub工程打包插件笤妙,而且過程非常簡單冒掌,可以非常方便的打造自己的maven倉庫
具體步驟
1.首先,添加buildscript了蹲盘,添加編譯插件股毫,可以添加在項(xiàng)目build.gradle,直接添加在當(dāng)前工程也可以
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
2.其次召衔,導(dǎo)入使用插件
apply plugin: 'com.github.dcendents.android-maven'
3.最后铃诬,添加腳本方法
// 打包源碼jar
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
}
// 打包文檔jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
完整參考
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 10001
versionName "1.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided 'com.android.support:appcompat-v7:23.+'
}
// 打包源碼jar
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
}
// 打包文檔jar
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives sourcesJar
archives javadocJar
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
附:官方GitHub
JItPack:https://github.com/jitpack
dcendents:https://github.com/dcendents
本作品采用知識共享署名-非商業(yè)性使用-相同方式共享 4.0 國際許可協(xié)議進(jìn)行許可。轉(zhuǎn)載請保留作者及原文鏈接