一、环境准备
安装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'