美文网首页
Maven私服Nexus搭建和使用

Maven私服Nexus搭建和使用

作者: redexpress | 来源:发表于2018-09-21 11:27 被阅读33次

一、环境准备

安装JDK

步骤略

二、安装Nexus 服务器

https://www.sonatype.com/nexus-repository-oss下载Nexus Repository OSS。
我下载的版本是nexus-3.13.0-01,进入目录nexus-3.13.0-01/bin目录,执行

./nexus start

即可启动Nexus
Nexus 默认的端口是8081,如果要更改端口可以修改etc/nexus-default.properties文件。
Nexus 管理管理员账户为admin,默认密码为admin123

三、Maven 和 Gradle 客户端配置

现在使用Maven和Gradle做构建工具都很普遍,下面分别说明两个工具的使用。

1、Maven配置

修改settings.xml 文件

Maven配置文件更改,修改<Maven安装目录>/conf/settings.xml文件,可以参考下面的文件:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
    <server>
      <id>nexus-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>nexus-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors>
    <mirror> 
      <id>nexus-public</id> 
      <mirrorOf>*</mirrorOf> 
      <url>http://localhost:8081/repository/maven-public</url> 
    </mirror>
  </mirrors>
</settings>

Maven项目的pom.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.github.redexpress</groupId>
  <artifactId>demo</artifactId>
  <version>1.0</version>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>
  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
  </dependencies>
  <distributionManagement>
      <repository>
          <id>nexus-releases</id>
          <url>http://localhost:8081/repository/maven-releases</url>
          <uniqueVersion>true</uniqueVersion>
      </repository>
      <snapshotRepository>
          <id>nexus-snapshots</id>
          <url>http://localhost:8081/repository/maven-snapshots</url>
      </snapshotRepository>
  </distributionManagement>
</project>

使用mvn deploy命令即可发布jar到Nexus 私服。

2、Gradle 配置

build.gradle

apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'io.github.redexpress'
version = '1.0'

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
     maven { url "http://repo.maven.apache.org/maven2" }
     maven { url "http://localhost:8081/repository/maven-public" }
}

publishing {
    repositories {
        maven {
            credentials {
                username 'admin'
                password 'admin123'
            }
            def releasesRepoUrl = 'http://localhost:8081/repository/maven-releases'
            def snapshotsRepoUrl = 'http://localhost:8081/repository/maven-snapshots'
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
        }
    }
    publications {
        maven(MavenPublication) {
            from components.java
        }
    }
}

dependencies {
    testCompile 'junit:junit:4.12'
}

settings.gradle

rootProject.name = 'demo'

相关文章

Maven私服Archiva搭建和使用

相关文章

  • CentOS7 搭建 nexus

    nexus是一种maven私服软件,很方便项目构建和管理。 本人使用的是nexus3的镜像的tar包,版本3.13...

  • Maven搭建私服Nexus

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

  • maven私服

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

  • Maven私服Nexus搭建和使用

    一、环境准备 安装JDK 步骤略 二、安装Nexus 服务器 从https://www.sonatype.com/...

  • Maven实战之nexus

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

  • 使用Nexus2搭建私有库

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

  • maven学习笔记

    1.maven环境配置2.配置maven3.maven私服 nexus3 配置4.maven使用nexus仓库5....

  • MAVEN中央仓库地址大全

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

  • maven中央仓库大全

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

  • Ubuntu server下搭建Maven私服Nexus

    Ubuntu server下搭建Maven私服Nexus Maven私服Nexus的作用,主要是为了节省资源,在内...

网友评论

      本文标题:Maven私服Nexus搭建和使用

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