maven中央服务器下载过慢;一个项目某些类被另一个项目使用,需要打包;持续集成也需要这些类
于是把这些类打包成jar放到maven私服上,使用snapshot版本,即时更新,另一个maven项目引用的jar包在编译的时候也会自动去对比版本并下载
安装过程
- 下载archiva-Standalone版本,解压至远程服务器任意文件夹。
- 运行[archiva_home]/bin/archiva start
- 输入IP:8080进入archiva界面进行注册
- 设置开发者终端的[maven_home]/conf/setting.xml
<servers>
<!-- omitted xml -->
<server>
<id>archiva.internal</id>
<!--archiva注册用户名密码-->
<username>admin</username>
<password>123456qwe</password>
</server>
<server>
<id>archiva.snapshots</id>
<username>admin</username>
<password>123456qwe</password>
</server>
<!-- omitted xml -->
</servers>
<mirrors>
<!-- omitted xml -->
<mirror>
<id>archiva.internal</id>
<url>http://192.168.1.99:8080/repository/internal/</url>
<mirrorOf>internal</mirrorOf>
</mirror>
<mirror>
<id>archiva.snapshots</id>
<url>http://192.168.1.99:8080/repository/snapshots/</url>
<mirrorOf>snapshots</mirrorOf>
</mirror>
<!-- omitted xml -->
</mirrors>
<profiles>
<!-- omitted xml -->
<profile>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>http://192.168.1.99:8080/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>internal</id>
<name>Archiva Managed Internal Repository</name>
<url>http://192.168.1.99:8080/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>archiva.snapshots</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<url>http://192.168.1.99:8080/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<name>Archiva Managed Snapshot Repository</name>
<!--远程服务器IP-->
<url>http://192.168.1.99:8080/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<!-- omitted xml -->
</profiles>
使用
- 设置项目pom.xml
<dependency>
<groupId>com.xxx.xxx</groupId>
<artifactId>model</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
...
<distributionManagement>
<repository>
<id>archiva.internal</id>
<url>http://192.168.1.99:8080/repository/internal/</url>
</repository>
<snapshotRepository>
<id>archiva.snapshots</id>
<url>http://192.168.1.99:8080/repository/snapshots/</url>
</snapshotRepository>
</distributionManagement>
- 上传自定义jar包至maven私服
mvn deploy:deploy-file -Dfile=model-3.0.0-SNAPSHOT.jar -DrepositoryId=archiva.internal -DgroupId=com.xxx.xxx -DartifactId=model -Dversion=3.0.0-SNAPSHOT -Durl=http://192.168.1.99:8080/repository/internal/
这样每次更新pom的时候就可以自动去maven私服上下载文件了