Nexus3.0.0+Maven的使用(三)

       这章主要讲怎么和Maven做集成,集成的方式主要分以下种情况:代理中央仓库、Snapshot包的管理、Release包的管理、第三方Jar上传到Nexus上

1  代理中央仓库

只要在PMO文件中配置私服的地址即可,配置如下:

<repositories>
		<repository>
			<id>maven-central</id>
			<name>maven-central</name>
			<url>http://10.0.1.42:8081/repository/maven-central/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
	</repositories>

  

2  Snapshot包的管理

1、  修改Maven的settings.xml文件,加入认证机制

<servers>
<server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
     </server>

 

2、  修改工程的Pom文件

<distributionManagement>
		<snapshotRepository>
			<id>nexus</id>
			<name>Nexus Snapshot</name>
			<url>http://10.0.1.42:8081/repository/maven-snapshots/</url>
		</snapshotRepository>
		<site>
			<id>nexus</id>
			<name>Nexus Sites</name>
			<url>dav:http://10.0.1.42:8081/repository/maven-snapshots/</url>
		</site>
	</distributionManagement>

  

注意事项:

截图中的名字要跟apache-maven-3.0.5-nexusconfsettings.xml的名字一定要对应上。

3、  上传到Nexus上

a)、项目编译成的jar是Snapshot(POM文件的头部)

<groupId>com.woasis</groupId>
<artifactId>test-nexus</artifactId>
<version>1.0.0-SHAPSHOT</version>
<packaging>jar</packaging>

  

b)、使用mvn deploy 即可,运行结果如图所示:

c、因为Snapshot是快照版本,默认他每次会把Jar加一个时间戳,做为历史备份版本。

3  Releases包的管理

a)、与Snapshot大同小异,只是上传到私服上的Jar包不会自动带时间戳,如图所示:

b)、与Snapshot配置不同的地方,就是工程的PMO文件,加入repository配置

<distributionManagement>
		<repository>
			<id>nexus</id>
			<name>Nexus Snapshot</name>
			<url>http://10.0.1.42:8081/repository/maven-releases/</url>
		</repository>

  

c)、打包的时候需要把Snapshot去掉,如图所示:

<groupId>com.woasis</groupId>
    <artifactId>test-nexus</artifactId>
    <version>1.0.0</version>
<packaging>jar</packaging>

  

4  第三方Jar上传到Nexus

mvn deploy:deploy-file -DgroupId=org.jasig.cas.client -DartifactId=cas-client-core -Dversion=3.1.3 -Dpackaging=jar -DrepositoryId=nexus -Dfile=D:cas-client-core-3.1.3.jar -Durl=http://10.0.1.42:8081/repository/maven-releases/-DgeneratePom=false

  

注意事项:

-DrepositoryId=nexus  对应的就是Maven中settings.xml的认证配的名字。

原文地址:https://www.cnblogs.com/qq27271609/p/5497815.html