zoukankan      html  css  js  c++  java
  • android studio发布公共类库到服务器maven仓库

    在上一篇中提到了怎么创建私有maven库,这篇主要结合android studio的使用,直接进入正题,看以下步骤

    1.创建android项目

    创建Project,然后加一个library的module,此处省略一万字了

    2.配置gradle

    在项目的gradle.properties里面配置基本信息

    GROUP=对应maven的groupId值,如果名字中包含SNAPSHOT字符,项目将会发布到snapshots仓库,没有则发布到releases仓库  
    VERSION_NAME=对应maven的version值  
    POM_ARTIFACT_ID=对应maven的artifactId值  
    SNAPSHOT_REPOSITORY_URL=前面配置的snapshots仓库地址  
    RELEASE_REPOSITORY_URL=前面配置的releases仓库地址  
    NEXUS_USERNAME=登录nexus oss的用户名
    NEXUS_PASSWORD=登录nexus oss的密码
    

    在module的build.gradle末尾加入下面代码

    apply plugin: 'maven'
    def isReleaseBuild() {
        return VERSION_NAME.contains("SNAPSHOT") == false
    }
    def getRepositoryUsername() {
        return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
    }
    def getRepositoryPassword() {
        return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
    }
    afterEvaluate { project ->
        uploadArchives {
            repositories {
                mavenDeployer {
                    pom.groupId = GROUP
                    pom.artifactId = POM_ARTIFACT_ID
                    pom.version = VERSION_NAME
                    repository(url: RELEASE_REPOSITORY_URL) {
                        authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                    }
                    snapshotRepository(url: SNAPSHOT_REPOSITORY_URL) {
                        authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
                    }
                }
            }
        }
        task androidJavadocs(type: Javadoc) {
            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.sourceFiles
        }
        artifacts {
            archives androidSourcesJar
            archives androidJavadocsJar
        }
    }

    3.发布公共库

    ./gradlew clean build uploadArchives

    就一条命令,最后成功就OK了,如果失败根据具体情况找原因。

    然后到nexus上查看是否上传成功

    4.使用

    在project中的build.gradle中的allprojects->repositories加入

    maven { url "http://192.168.59.103:8081/content/repositories/releases/" }

    在module的build.gradle中的dependencies加入

    compile 'groupId:artifactId:version'
    groupId,artifactId,version换成你自己的

    build一切OK。

    如有疑问欢迎交流
  • 相关阅读:
    Treap 树堆 容易实现的平衡树
    (转)Maven实战(二)构建简单Maven项目
    (转)Maven实战(一)安装与配置
    根据请求头跳转判断Android&iOS
    (转)苹果消息推送服务器 php 证书生成
    (转)How to renew your Apple Push Notification Push SSL Certificate
    (转)How to build an Apple Push Notification provider server (tutorial)
    (转)pem, cer, p12 and the pains of iOS Push Notifications encryption
    (转)Apple Push Notification Services in iOS 6 Tutorial: Part 2/2
    (转)Apple Push Notification Services in iOS 6 Tutorial: Part 1/2
  • 原文地址:https://www.cnblogs.com/lping/p/5531285.html
Copyright © 2011-2022 走看看