maven自动打包上传nexus仓库配置

一个基础类,可能要升级并放到私服库里,为了方便,应该能够自动打包放到nexus。这就需要配置maven一些参数与pom.xml。

依次在settings.xml文件裡輸入

Xml代码  收藏代码
  1.  <!-- nexus帳號和密碼-->  
  2.   
  3.    <server>    
  4.      <id>releases</id>    
  5.      <username>admin</username>    
  6.      <password>admin123</password>    
  7.    </server>    
  8.    <server>    
  9.      <id>snapshots</id>    
  10.      <username>admin</username>    
  11.      <password>admin123</password>    
  12.    </server>       
  13.  </servers>    
  14.   
  15. ...  
  16.   
  17. <!-- 引用naxus倉庫組-->  
  18.    <profile>  
  19.        <id>dev</id>  
  20.           <repositories>  
  21.              <repository>  
  22.                  <id>nexus</id>  
  23.                  <url>http://127.0.0.1:8081/nexus/content/groups/public/</url>  
  24.                  <releases>  
  25.                     <enabled>true</enabled>  
  26.                  </releases>  
  27.                  <snapshots>  
  28.                     <enabled>true</enabled>  
  29.                  </snapshots>  
  30.               </repository>  
  31.             </repositories>             
  32.             <pluginRepositories>  
  33.                 <pluginRepository>  
  34.                     <id>nexus</id>  
  35.                     <url>http://127.0.0.1:8081/nexus/content/groups/public</url>  
  36.                     <releases>  
  37.                         <enabled>true</enabled>  
  38.                     </releases>  
  39.                     <snapshots>  
  40.                         <enabled>true</enabled>  
  41.                     </snapshots>  
  42.                 </pluginRepository>  
  43.             </pluginRepositories>  
  44.         </profile>  
  45. ..  
  46.   
  47.  <!-- nexus -->  
  48.   <activeProfiles>  
  49.         <activeProfile>dev</activeProfile>  
  50.   
  51.     </activeProfiles>   


注意:根據標籤位置準確輸入

 

在本项目的pom.xml配置即可 
<!--上传配置 必须--> 

<distributionManagement>
<repository>
<id>releases</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<!--上传source.jar 非必须-->

<build>

<plugins>

<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-source-plugin</artifactId>

<executions>

<execution>

<id>attach-sources</id>

<goals>

<goal>jar</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

上面的ID和pom.xml中对应distributionManagement-> repository的ID,用户名和密码需要在nexus中配置。

完成以上配置,只要输入命令:mvn deploy 即可。

 

遇到的问题:

maven deploy到nexus报错:Return code is: 401, ReasonPhrase:Unauthorized

提交到nexus时候报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project *: Failed to deploy artifacts: Could not transfer artifact *:jar:1.0 from/to releases (http://10.1.81.199:8081/nexus/content/repositories/releases/): Failed to transfer file: http://10.1.81.199:8081/nexus/content/repositories/releases/com/cs2c/security-management-client* /1.0/*-1.0.jar. Return code is: 401, ReasonPhrase:Unauthorized.

原来是没有配置认证。

maven目录conf的setting.xml里,

  1.   <server>  
  2.     <id>releases</id>  
  3.     <username>admin</username>  
  4.     <password>admin123</password>  
  5.   </server>  
  6.  <server>  
  7.   <id>snapshots</id>  
  8.   <username>admin</username>  
  9.   <password>admin123</password>  
  10.   </server>  
  11. </servers>  

用户名和密码都是nexus的。再次deploy即可。

注意这里的id要和pom.xml里远程deploy的地址对应一致,我的pom.xml里配置:

 

    1. <!-- 配置远程发布到私服,mvn deploy -->  
    2.     <distributionManagement>  
    3.         <repository>  
    4.             <id>releases</id>  
    5.             <name>Nexus Release Repository</name>  
    6.             <url>http://10.1.81.199:8081/nexus/content/repositories/releases/</url>  
    7.         </repository>  
    8.         <snapshotRepository>  
    9.             <id>snapshots</id>  
    10.             <name>Nexus Snapshot Repository</name>  
    11.             <url>http://10.1.81.199:8081/nexus/content/repositories/snapshots/</url>  
    12.         </snapshotRepository>  
    13.     </distributionManagement>  

-------------------------------------------------------

<?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>releases</id>
<username>adminxxx</username>
<password>{xxxx}</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>{xxxxxxx}</password>
</server>
<server>
<id>uepay</id>    
<username>deploy_xxxxxuser</username>
<password>xxx</password>
</server>
</servers>
<mirrors>
<mirror>
<id>uepay</id>
<mirrorOf>*</mirrorOf>
<name>Nexus uepay</name>
<url>http://192.168.x.xx:8082/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>uepay</id>
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.x.xx:8082/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<url>http://192.168.xx.xx:8082/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>uepay</activeProfile>
</activeProfiles>

</settings

 

注意id对应的的授权

posted @ 2017-12-19 18:02  技术颜良  阅读(402)  评论(0编辑  收藏  举报