android nexus私服的使用

作者: LaxusJ | 来源:发表于2017-12-05 00:34 被阅读141次

先唠叨几句啊,由于公司私服已经搭好了我就不费那劲琢磨搭建私服的事了,直接开撸上传lib。下图是我放组件库的地方,本来想一个module拉出一个项目来维护,后来想想实在是麻烦,同时维护多个库就要down多个库下来,于是就统一管理了。当然统一维护module多了自然会影响编译的速度,可以在settings.gradle 里将不编译的module注释掉就可以了。现在就有图片选择、表情、输入框、星星、视频录制、裁切等七七八八个库,至于后面组件库多了可能会分类按类型拉出几个项目来管理,要不版本控制也是个麻烦事。目前就是升级一个module在git上打个tag标签。大家有啥好的建议欢迎留言哈。

项目展示.png

发布Library到私服

我们就以functionbar这个组件库为例吧

配置nexus账户信息

因为Nexus相关参数是固定的,包含仓库地址、用户名和密码,从安全性考虑我们把这些参数写到gradle的Global配置中,目录是C:\Users(用户名).gradle\gradle.properties

NEXUS_USERNAME=username
NEXUS_PASSWORD=password
NEXUS_REPOSITORY_URL=http://xxx/nexus/repository/maven-releases/

配置pom参数

项目根目录下的gradle.properties中添加如下pom参数

//依赖库名称
POM_NAME=functionbar
//版本号
POM_VERSION=1.0.1
//类别
POM_ARTIFACTID=utils
//组id
POM_GROUPID=com.app
//打包类型
POM_PACKAGING=aar

引入gradle脚本

在library的build.gradle文件末尾加上如下引用,当然这个文件需要创建放到项目根路径,源码在脚本解读

apply from: '../nexus_upload.gradle'

这个nexus_upload.gradle脚本包含生成java-source和java-doc,如果注释不完整可以注释掉脚本里的androidJavadocsJar调用,避免影响上传。

发布

双击右侧gradle task中的uploadArchives,编译并上传library

up.png

等待一会出现Success字样,证明已经上传成功

success.png

最后我们去Nexus上验证下,bingo!上传成功。

QQ截图20171205001920.png

脚本解读

//依赖maven插件
apply plugin: 'maven'

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

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

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

artifacts {
    archives androidSourcesJar
    //如果项目javadoc不全会报错,可以注释掉
    archives androidJavadocsJar
}

uploadArchives {
    repositories {
        mavenDeployer {
            //仓库地址
            repository(url: NEXUS_REPOSITORY_URL) {
                //私服账户信息
                authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
            }
            //pom必需的参数
            pom.project {
                name POM_NAME
                version POM_VERSION
                artifactId POM_ARTIFACTID
                groupId POM_GROUPID
                packaging POM_PACKAGING
            }
        }
    }
}

使用私服上的Library

首先,要在项目的build.gradle里面声明私服的地址

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url NEXUS_REPOSITORY_URL}
    }
}

然后就是我们最熟悉的在module的build.gradle文件中添加依赖,注意 groupId后面是:依赖库名称后面要加:和版本号,我就犯过引用是groupId后面写. 的错误。

compile 'com.app:functionbar:1.0.1

发布Plugin(插件)到私服

发布步骤是和library一样的只不过需要提一点,脚本信息需要做一些删减,只用到以下这些。

apply plugin: 'maven'
uploadArchives {
    repositories {
        mavenDeployer {
            //仓库地址
            repository(url: NEXUS_REPOSITORY_URL) {
                //私服账户信息
                authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
            }
            //pom必需的参数
            pom.project {
                name POM_NAME
                version POM_VERSION
                artifactId POM_ARTIFACTID
                groupId POM_GROUPID
                packaging POM_PACKAGING
            }
        }
    }
}

使用私服上的Plugin

首先,要在项目的build.gradle里面配置classpath引用,就拿经典的小刀举例吧

buildscript {
    
    repositories {
        jcenter()
        maven { url  NEXUS_REPOSITORY_URL}
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
        ...
    }
}

然后在module中build.gradle引用插件plugin

apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.butterknife'

相关文章

  • maven私服

    使用私服 Maven 自动打包上传到私服 Nexus 自动打包上传私服(nexus3.X版本改了很多) Repos...

  • Maven搭建私服Nexus

    一、搭建Maven私服,使用Nexus搭建1、下载Nexus,点击nexus下载,下载nexus-2.13.0-0...

  • android nexus私服的使用

    先唠叨几句啊,由于公司私服已经搭好了我就不费那劲琢磨搭建私服的事了,直接开撸上传lib。下图是我放组件库的地方,本...

  • 使用 Nexus 搭建 Maven 私服

    使用 Nexus 搭建 Maven 私服 一、Nexus 服务的安装 Nexus 既可以使用传统的二进制包进行安装...

  • maven

    仓库地址 : 1、http://www.sonatype.org/nexus/ 私服nexus工具使用 2、htt...

  • MAVEN中央仓库地址大全

    Maven 中央仓库地址: 1、私服nexus工具使用 http://www.sonatype.org/nexus...

  • maven中央仓库大全

    Maven 中央仓库地址: 1、私服nexus工具使用 http://www.sonatype.org/nexus...

  • 使用Nexus2搭建私有库

    本文梳理了一些使用Nexus搭建Maven私服的方法。Maven私服Nexus的作用,主要是为了节省资源,在内部作...

  • Maven实战之nexus

    使用专门的Maven仓库管理软件Nexus构建Maven私服。 nexus下载地址 https://www.son...

  • java Nexus私服

    Nexus私服

网友评论

    本文标题:android nexus私服的使用

    本文链接:https://www.haomeiwen.com/subject/dxzfixtx.html