Archiva與maven配置使用

在以前的博文裏頭已經介紹了Archiva私服的使用,本文主要介紹,如何與maven進行配置,在進行maven使用的時候能夠自動上傳至Archiva上git

一、設置maven的用戶配置,到maven的安裝目錄下/conf/setting.xml,參考如下配置修改:github

1.1 認證信息就是你在倉庫管理中設置的user,而在本地,須要在<servers>標籤下新增<server>:apache

    <server>
      <id>archiva.internal</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    
     <server>
      <id>archiva.snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>

1.2 設置存儲鏡像服務器

    <mirror>
      <id>archiva.internal</id>
      <mirrorOf>internal</mirrorOf>
      <name>internal</name>
      <url>http://118.24.48.158:8088/repository/internal/</url>
    </mirror>
    <mirror>
      <id>archiva.snapshots</id>
      <mirrorOf>snapshots</mirrorOf>
      <name>snapshots</name>
      <url>http://118.24.48.158:8088/repository/snapshots/</url>
    </mirror>

1.3 這裏有兩種方式,第一種是將私有倉庫做爲惟一的倉庫使用(私有倉庫做爲遠程倉庫的代理使用);第二種是將私有倉庫做爲倉庫列表中的一個使用。考慮到筆者所處的網絡環境,因此選擇了第二種方式 。 網絡

在<settings>標籤的<profiles>下增長一個新的<profile>:app

<profile>
      <id>archiva.internal</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
          <id>internal</id>
          <name>Archiva Managed Internal Repository</name>
          <url>http://118.24.48.158:8088/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://118.24.48.158:8088/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://118.24.48.158:8088/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://118.24.48.158:8088/repository/snapshots/</url>
          <releases>
            <enabled>false</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
     </profile>

1.4 在項目的pom.xml文件裏頭新增倉庫maven

  <distributionManagement>
   <repository>
     <id>archiva.internal</id>
     <url>http://192.168.43.45:8080/repository/internal/</url>
   </repository>
   <snapshotRepository>
     <id>archiva.snapshots</id>
     <url>http://192.168.43.45:8080/repository/snapshots/</url>
   </snapshotRepository>
 </distributionManagement>

注意:這裏的id要和<server>中配置的id一致。ui

二、新建一個maven項目,參考步驟1配置相關屬性,而後在控制檯輸入命令:url

mvn clean install deploy

相關的war已經上傳Archiva私服上,咱們到私服看下:spa

附件:maven工程能夠參考git:https://github.com/shawwey/testJenkins

pom參考以下:

一、internal版本存儲:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fjnx.cn</groupId>
  <artifactId>testJenkins</artifactId>
  <packaging>war</packaging>
  <version>1.0.0</version>
  <name>testJenkins Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>testJenkins</finalName>
  </build>
  <distributionManagement>
   <repository>
     <id>archiva.internal</id>
     <url>http://192.168.43.45:8080/repository/internal/</url>
   </repository>
   <snapshotRepository>
     <id>archiva.snapshots</id>
     <url>http://192.168.43.45:8080/repository/snapshots/</url>
   </snapshotRepository>
 </distributionManagement>
</project>

二、snapshots快照版本,區別所在只是版本後面加個"-SANPSHOT"

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fjnx.cn</groupId>
  <artifactId>testJenkins</artifactId>
  <packaging>war</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <name>testJenkins Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <finalName>testJenkins</finalName>
  </build>
  <distributionManagement>
   <repository>
     <id>archiva.internal</id>
     <url>http://192.168.43.45:8080/repository/internal/</url>
   </repository>
   <snapshotRepository>
     <id>archiva.snapshots</id>
     <url>http://192.168.43.45:8080/repository/snapshots/</url>
   </snapshotRepository>
 </distributionManagement>
</project>

done!

相關文章
相關標籤/搜索