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

Maven私服Archiva搭建和使用

作者: redexpress | 来源:发表于2018-09-22 10:35 被阅读220次

一、环境准备

安装JDK

步骤略

二、安装Archiva服务器

https://archiva.apache.org下载Archiva。
进入bin目录执行archiva start即可启动Archiva。
Nexus 默认的端口是8080,如果要更改端口可以修改conf/jetty文件。
启动Archiva会要求设置管理员账户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>archiva-releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>archiva-snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors>
    <mirror> 
      <id>archiva-releases</id> 
      <mirrorOf>internal</mirrorOf> 
      <url>http://localhost:8080/repository/internal</url> 
    </mirror>
    <mirror> 
      <id>archiva-snapshots</id>
      <mirrorOf>snapshots</mirrorOf> 
      <url>http://localhost:8080/repository/snapshots</url> 
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>internal</id>
          <name>Archiva Managed Internal Repository</name>
          <url>http://localhost:8080/repository/internal</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>snapshots</id>
          <name>Archiva Managed Snapshots Repository</name>
          <url>http://localhost:8080/repository/snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>
</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>archiva-releases</id>
          <url>http://localhost:8080/repository/internal</url>
          <uniqueVersion>true</uniqueVersion>
      </repository>
      <snapshotRepository>
          <id>archiva-snapshots</id>
          <url>http://localhost:8080/repository/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:8080/repository/internal" }
     maven { url "http://localhost:8080/repository/snapshots" }
}

publishing {
    repositories {
        maven {
            credentials {
                username 'admin'
                password 'admin123'
            }
            def releasesRepoUrl = 'http://localhost:8080/repository/internal'
            def snapshotsRepoUrl = 'http://localhost:8080/repository/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私服Nexus搭建和使用

相关文章

  • Maven私服Archiva搭建和使用

    一、环境准备 安装JDK 步骤略 二、安装Archiva服务器 从https://archiva.apache.o...

  • docker 搭建 nexus

    一、有三种专门的Maven仓库管理软件可以用来帮助大家建立私服:Apache基金会的Archiva、JFrog的A...

  • Maven私服搭建

    什么是maven私服? 工程中如何使用? 如何接入maven私服? 了解maven私服 分为本地和远程 远程包括:...

  • Maven私服Nexus搭建和使用

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

  • Maven(5)Nexus

    前言 Maven是Java项目管理的利器,使用私服来管理Maven仓库是Maven使用的一条最佳实践。私服是内网的...

  • maven私服

    1、配置本地maven settings.xml 使用私服 2、发布jar到私服配置本地maven setting...

  • maven私服管理

    maven工程使用私服中需要添加repository 私服会有密码,所以需要在maven的settings文件中加...

  • 【maven】私服jar包引用和上传

    背景:昨天同事让我帮忙往私服里上传jar包,方便大家一起使用,特此研究maven私服相关。 maven私服简介 m...

  • CentOS7 搭建 nexus

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

  • Maven私服Nexus的搭建和使用(Mac)

    (一部分2.x版本)1.下载对应的安装包https://www.sonatype.com/oss-thank-yo...

网友评论

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

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