手记

mac上搭建nexus环境给安卓搭建moven环境

打开网站https://www.sonatype.com/download-oss-sonatype下载mac版nexus


我们通过termial进入nexus-3.16-02,然后进入bin目录,执行

然后就可以打开http://192.168.118.45:8081/,用户名和密码是admin/admin123


如何上传一个aar到nexus里呢,在项目中建立一个library包,在build.gradle中加入

apply from: 'mvn.gradle'


然后增加mvn.gradle文件,内容是:

apply plugin: 'maven'

uploadArchives {
    configuration = configurations.archives

    repositories {
        mavenDeployer {
            if (MVN_RELEASE == 'product') {
                repository(url: uri(MVN_RL_URL)) {
                    authentication(userName: MVN_NAME, password: MVN_PASS)
                }
                pom.project {
                    version MVN_VERSION
                    artifactId MVN_ARTIFACT_ID
                    groupId MVN_GROUP_ID
                    packaging MVN_PACKAGING
                }
            } else if (MVN_RELEASE == 'snapshot') {
                repository(url: uri(MVN_SN_URL)) {
                    authentication(userName: MVN_NAME, password: MVN_PASS)
                }
                pom.project {
                    version MVN_VERSION + "-SNAPSHOT"
                    artifactId MVN_ARTIFACT_ID
                    groupId MVN_GROUP_ID
                    packaging MVN_PACKAGING
                }
            } else if (MVN_RELEASE == 'local') {
                repository(url: uri("build/aar"))
                pom.project {
                    version MVN_VERSION
                    artifactId MVN_ARTIFACT_ID
                    groupId MVN_GROUP_ID
                    packaging MVN_PACKAGING
                }
            } else {
                project.println("do nothing for task uploadArchives")
            }
        }
    }
}

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

artifacts {
    archives androidSourcesJar
}

然后在主工程的gradle.properties里加入:

org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
MVN_ARTIFACT_ID=basemodule
MVN_GROUP_ID=com.imooc.basemodule
MVN_RL_URL=http://192.168.118.45:8081/repository/maven-releases/
MVN_SN_URL=http://192.168.118.45:8081/repository/maven-snapshots/


MVN_NAME=admin
MVN_PASS=admin123

MVN_PACKAGING=aar

MVN_RELEASE=snapshot
MVN_VERSION=1.4.8.7

然后点击

就会生成jar包:

如何在项目中进行使用呢:

在主工程的moven中加入:

然后compile的时候使用

compile 'com.nick.module:emotion:1.4.8.6-SNAPSHOT'

就行了

0人推荐
随时随地看视频
慕课网APP