上传库到jcenter中央仓库

上传库到jcenter中央仓库

参考链接:https://blog.csdn.net/wangqiubo2010/article/details/77646461

先说碰到的问题吧!

Q1、Plugin with id ‘com.github.dcendents.android-maven’ not found.

解决:在项目根目录下添加“classpath ‘com.github.dcendents:android-maven-gradle-plugin:1.4.1’”

Q2、Plugin with id ‘com.jfrog.bintray’ not found.

解决:在项目根目录下添加“ classpath ‘com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+’”

第一步

说实话,在网上看到了很多文章,可以最后到运行总是很多坑出来,最后自己也无奈了,不知道该怎么办了,只能一个问题一个问题的去解决吧,最后总结出来了三个文件,这三个是比较重要的文件:

第一个:根目录下local.properties文件

在这个文件内放入了一个共有参数,像userId、apikey什么的都放在了里面,然后直接上代码

ndk.dir=C\:\\Develop\\Tools\\Android\\AndroidSdk\\ndk-bundle
sdk.dir=C    \:\\Develop\\Tools\\Android\\AndroidSdk
bintray.user = xxxx
bintray.apikey = xxxxxxxxx
bintray.gpg.password = xxxx
#开发者的id
userinfo.userId = "xxxxx" 
#开发者名字
userinfo.userName = "xxxxx" 
#开发者邮箱
userinfo.userEmail = "xxxxxxxx"
#Git仓库地址
project.gitUrl = "git@xxxxxxxxxx"
#项目主页
project.webSiteUrl = "https://github.com/Loren-Wang" 
#项目group群组名称compile 'com.github.lorenwang:JavaCustomToolsFromLorenWang:1.0.0' 第一个分号签名的部分
project.groupId = "com.github.lorenwang" 


#gradle内容读取示例
#def bintrayUser = properties.getProperty("bintray.user")
#def bintrayKey = properties.getProperty("bintray.apikey")
#def bintrayGpgPwd = properties.getProperty("bintray.gpg.password")
#def userId = properties.getProperty("userinfo.userId")
#def userName = properties.getProperty("userinfo.userName")
#def userEmail = properties.getProperty("userinfo.userEmail")
#def projectGitUrl = properties.getProperty("project.gitUrl")
#def projectWebsiteUrl = properties.getProperty("project.webSiteUrl")

第二个:(Android)module目录下build.gradle

这个文件主要是为了存储着一些脚本代码,这个脚本代码会读取第一个文件文件当中的一些通用配置信息,然后进行一些参数配置,用来生成jar包以及pom文件,最后上传代码时实际上上传的就是这个文件,在配置时还有一些其他的参数,是和每个module相关的,所以暂时就没有说将通用部分抽取出来,代码如下:

apply plugin: 'com.android.library'
//必须引入这2个插件
apply plugin : 'com.github.dcendents.android-maven'
apply plugin : 'com.jfrog.bintray'

android {
    compileSdkVersion 28


    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}



def moduleName = "AndroidAnimFromLorenWang"
def moduleDescription = "Android自定义动画资源库"
version '1.0.0'
Properties properties = new Properties();
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def bintrayUser = properties.getProperty("bintray.user")
def bintrayKey = properties.getProperty("bintray.apikey")
def bintrayGpgPwd = properties.getProperty("bintray.gpg.password")
def userId = properties.getProperty("userinfo.userId")
def userName = properties.getProperty("userinfo.userName")
def userEmail = properties.getProperty("userinfo.userEmail")
def projectGitUrl = properties.getProperty("project.gitUrl")
def projectWebsiteUrl = properties.getProperty("project.webSiteUrl")
def projectGroupId = properties.getProperty("project.groupId")
def muduleVersion = version

install{
    repositories.mavenInstaller {
        // 生成pom.xml和参数
        pom {
            project {
                packaging 'aar'
                // 项目描述,复制我的话,这里需要修改。
                name moduleName// 可选,项目名称。
                description moduleDescription// 可选,项目描述。
                url projectWebsiteUrl // 项目主页,这里是引用上面定义好。

                // 软件开源协议,现在一般都是Apache License2.0吧,复制我的,这里不需要修改。
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                //填写开发者基本信息,复制我的,这里需要修改。
                developers {
                    developer {
                        id userId// 开发者的id。
                        name userName // 开发者名字。
                        email userEmail // 开发者邮箱。
                    }
                }

                // SCM,复制我的,这里不需要修改。
                scm {
                    connection projectGitUrl // Git仓库地址。
                    developerConnection projectGitUrl // Git仓库地址。
                    url projectWebsiteUrl // 项目主页。
                }
                 dependencies{
                    dependency{
                        groupId projectGroupId
                        version muduleVersion
                        artifactId moduleName
                   }
               }
            }
        }
    }
}

//这部分代码为是否要生成源码以及javadoc,不需要刻意注释掉
// 生成jar包的task,不需要修改。
task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    classifier = 'sources'
}
// 生成jarDoc的task,不需要修改。
task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += configurations.compile
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    // destinationDir = file("../javadoc/")
    failOnError false // 忽略注释语法错误,如果用jdk1.8你的注释写的不规范就编译不过。
}
// 生成javaDoc的jar,不需要修改。
task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}
artifacts {
    archives javadocJar
    archives sourcesJar
}
//这部分代码为是否要生成源码以及javadoc,不需要刻意注释掉


bintray {
    user = bintrayUser
    key = bintrayKey
    configurations = ['archives']
group = projectGroupId
version = muduleVersion

    pkg {
        repo = "maven"
        name = moduleName
        websiteUrl = projectWebsiteUrl
        vcsUrl = projectGitUrl
        licenses = ["Apache-2.0"]
        publish true
        version{
            gpg{
                sign = true
                passphrase = bintrayGpgPwd
            }
        }
    }
}
repositories {
    mavenCentral()
}

首先两个重要的插件是要导入的,至于如果导入后报错那么参考文章最顶部的问题,其次,有些代码我注释掉了,因为对于我个人来说用不到,至于含义大家可以参考其他文章,然后我的文件生成以及文件上传后面我会讲下的。

第三个:(Java)module目录下build.gradle

这个和第二个文件讲的一致,只不过部分代码不太一致,所以贴了出来,他是可以直接把自己制作的纯java非android文件格式的代码生成并上传。

plugins{
    id 'java'
    id 'com.jfrog.bintray'
    id 'com.github.dcendents.android-maven'
}
sourceSets{
    main{
        java.srcDirs = ['src']
    }
}
sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

def moduleName = "JavaCustomToolsFromLorenWang"
def moduleDescription = "java自定义工具库"
version '1.0.0'
Properties properties = new Properties();
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def bintrayUser = properties.getProperty("bintray.user")
def bintrayKey = properties.getProperty("bintray.apikey")
def bintrayGpgPwd = properties.getProperty("bintray.gpg.password")
def userId = properties.getProperty("userinfo.userId")
def userName = properties.getProperty("userinfo.userName")
def userEmail = properties.getProperty("userinfo.userEmail")
def projectGitUrl = properties.getProperty("project.gitUrl")
def projectWebsiteUrl = properties.getProperty("project.webSiteUrl")
def projectGroupId = properties.getProperty("project.groupId")

install{
    repositories.mavenInstaller {
        // 生成pom.xml和参数
        pom {
            project {
                packaging 'aar'
                // 项目描述,复制我的话,这里需要修改。
                name moduleName// 可选,项目名称。
                description moduleDescription// 可选,项目描述。
                url projectWebsiteUrl // 项目主页,这里是引用上面定义好。

                // 软件开源协议,现在一般都是Apache License2.0吧,复制我的,这里不需要修改。
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                //填写开发者基本信息,复制我的,这里需要修改。
                developers {
                    developer {
                        id userId// 开发者的id。
                        name userName // 开发者名字。
                        email userEmail // 开发者邮箱。
                    }
                }

                // SCM,复制我的,这里不需要修改。
                scm {
                    connection projectGitUrl // Git仓库地址。
                    developerConnection projectGitUrl // Git仓库地址。
                    url projectWebsiteUrl // 项目主页。
                }
            }
        }
    }
}
//
//task sourcesJar(type : Jar) { //这个task不需要修改,发布内容为jar类型
//    classifier = 'sources'
//}
//
//task javadocJar(type : Jar, dependsOn : javadoc) { //这里也不需要修改
//    classifier = 'javadoc'
//    from javadoc.destinationDir
//}
//
//artifacts { //这里不需要修改,发布内容包括javadocJar和sourcesJar
//    archives javadocJar
//    archives sourcesJar
//}

bintray {
    user = bintrayUser
    key = bintrayKey
    configurations = ['archives']

    pkg {
        repo = "maven"
        name = moduleName
        websiteUrl = projectWebsiteUrl
        vcsUrl = projectGitUrl
        licenses = ["Apache-2.0"]
        version{
            gpg{
                sign = true
                passphrase = bintrayGpgPwd
            }
        }
    }
}

第二步

其实上面两个文件添加完成之后主要工作就已经完成了一大部分,剩下的就交个intellij idea就可以了。

首先 gradlew clean这一步如果用idea的话其实可有可无了,因为之所以要执行clean这个命了其实就是为了将以前的生成还有其他module的生成清理掉,防止上传的时候重复上传,但是idea在上传这一步是可以针对于module进行上传的,这个上传方式后面再说,下面再说说第二步吧。

第二步就是执行gradlew install 命令,用来生成jar以及pom包的,这个用idea用命令行都可以,区别就在于是整个项目全部生成还是单个module生成,看个人喜好,我是直接使用的idea进行单项目生成的,直接在module的build.gradle当中的install左侧的执行按钮执行即可,如下图:

在这里插入图片描述
第三步就是上传了,上传的命令使用的是gradlew bintrayUpload命令,但是不知道为啥我使用这个总是再报错,而且还是报以前打的包错误,明明已经都清除了不知道为啥还在报错,所以干脆就不管了,直接使用单module项目包上传,在idea的右侧gradle工作区里面选中你要上传的项目,然后选中publishing项目,下面有个bintrayupload选中,点击运行就可以单独把这个项目上传,如下图:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值