Jcenter工程上传

1.将upload.gradle复制到要发布的module目录下;

apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

version = libraryVersion
group = publishedGroupId// Maven Group ID for the artifact

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

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}


artifacts {
//    archives androidJavadocs
    archives androidSourcesJar
}

// Bintray
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
    user = properties.getProperty("bintray.user")
    key = properties.getProperty("bintray.apikey")

    configurations = ['archives']
    pkg {
        repo = bintrayRepo
        name = bintrayName
        desc = libraryDescription
        websiteUrl = siteUrl
        vcsUrl = gitUrl
        licenses = allLicenses
        publish = true
        publicDownloadNumbers = true
        version {
            desc = libraryDescription
            gpg {
                sign = true //Determines whether to GPG sign the files. The default is false
                passphrase = properties.getProperty("bintray.gpg.password")
                //Optional. The passphrase for GPG signing'
            }
        }
    }
}

install {
    repositories.mavenInstaller {
        // This generates POM.xml with proper parameters
        pom {
            project {
                packaging 'aar'
                groupId publishedGroupId
                artifactId artifact

                // Add your description here
                name libraryName
                description libraryDescription
                url siteUrl

                // Set your license
                licenses {
                    license {
                        name licenseName
                        url licenseUrl
                    }
                }
                developers {
                    developer {
                        id developerId
                        name developerName
                        email developerEmail
                    }
                }
                scm {
                    connection gitUrl
                    developerConnection gitUrl
                    url siteUrl

                }
            }
        }
    }
}

 

2.在项目根build.gradle中增加

        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.1'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'//这个插件的版本会跟着gradle版本有变化,如果不相符,会有Plugin with id 'com.github.dcendents.android-maven' not found
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }

 

3.在local.properties中增加

bintray.user=xxxx //jcenter上的用户名
bintray.apikey=xxxxxxx //在用户信息编辑页面中有一个ApiKey

4.在要发布的module的build.gradle中增加

ext {
    //项目地址
    siteUrl = 'https://github.com/qwerttest/ShareLoginCharge'
    //项目下载地址
    gitUrl = 'https://github.com/qwerttest/ShareLoginCharge.git'

    //要发布的仓库,需要在jCenter中创建
    bintrayRepo = 'maven'
    //在maven仓库中创建的工程的名字
    bintrayName = 'loginShareCharge'

    //要发布到的group的标识,使用module包名即可
    publishedGroupId = 'com.android.frame.third.library'
    //libraryName, artifact, moduleName必须保持一致
    libraryName = 'library'
    //artifactId 要发布的工程的标识
    artifact = 'library'
    libraryDescription = 'this is a test'//项目描述
    //要发布的版本号
    libraryVersion = '1.0.0'

    //发布者的信息
    developerId = 'jin'
    developerName = 'jin'
    developerEmail = 'wj19890810@gmail.com'

    //许可信息,不用修改
    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}

apply from:'upload.gradle

5.配置完成后,在terminal中执行

gradlew.bat install

successful之后再执行:

gradlew.bat bintrayUpload

都执行成功后便成功发布到了maven库中。

6.这时,如果想使用发布的项目,还需要在工程的根build.gradle中加入

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://dl.bintray.com/thelasterstar/maven/" }//添加此句
    }
}
maven { url "https://dl.bintray.com/thelasterstar/maven/" }//添加此句
    }
}

或者在app中的build.gradle中加入

repositories {
    maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}

现在,就可以在

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.frame.third.library:library:1.0.0'//这个是发布的工程
}


引入使用了。

7.如果要想不加入6步骤,则需要将项目join jcenter中:

提交之后审核大概3-4个小时,也可能很短。审核通过之后就可以很方便地使用了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值