mac nexus搭建本地maven服务器

 

 

 

1.在保证安装jdk 1.7+,去nexus官网下载nexus(http://www.sonatype.com/download-oss-sonatype) 最新版本java

2.解压zip文件,配置nexus下bin目录全局变量 打开.bash_profile添加以下 android

export PATH=${PATH}:/Users/mac/Documents/software/nexus-3.6.0-02-mac/nexus-3.6.0-02/binapache

3.进入到bin目录后./nexus start启动nexus, 浏览器打开http://localhost:8081/nexus/ 若是能成功访问。则说明安装成功了,界面以下:浏览器

咱们在设置里面能够新建仓库bash

填写仓库名称等一些信息app

接下来 咱们安装maven 下载地址 http://maven.apache.org/download.cgimaven

一样配置maven bin目录全局变量gradle

export PATH=${PATH}:/Users/mac/Documents/software/apache-maven-3.5.2/binui

打开maven下面的conf文件夹后 打开settings.xml添加以下代码url

<server>

       <id>仓库id</id>

          <username>admin</username>

          <password>admin123</password>

</server>

 

<mirror>

        <id>nexus</id>

        <mirrorOf>仓库id</mirrorOf>

        <name>Nexus Mirror</name>

        <url>仓库url地址</url>

</mirror>

 

4.发布带有pom的jar包

命令以下:

mvn deploy:deploy-file -DpomFile=<path-to-pom> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
 
5.发布不带pom文件的独立jar包:
命令以下:
mvn deploy:deploy-file -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<type-of-packaging> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
 
6.上传android studio library

build.gradle中添加代码:

apply from: './nexus-push.gradle'

在同级目录下建立一个nexus-push.gradle文件,代码以下:

apply plugin: 'maven'

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


artifacts {
    archives androidSourcesJar
}
uploadArchives {
    repositories {
        mavenDeployer {

            repository(url: "http://127.0.0.1:9999/nexus-zip/repository/maven-releases/") {
                authentication(userName: "admin", password: "123456")      //帐号,密码
            }
            pom.project {

      //groupId:惟一标识符
      //artifactId:相似于项目名称
      //version:版本号
                version '1.0.3'
                artifactId 'xxxxid'
                groupId 'cn.xxx.android'
                packaging 'aar'
                description 'dependences lib'

            }
        }
    }
}

Terminal命令上传

gradlew uploadArchives

表示上传成功,能够在最初创建的仓库下看到你上传的文件了。若是有问题,请留言,咱们一块儿讨论。