2016-08-11 81 views
0

我使用Redhatjava 1.7maven 3.2.5jenkins 1.6git version 2.0.5nexus-2.12.0-01如何配置pom.xml文件中使用的Nexus存儲庫管理

我創建了一個本地Nexus Repository我的內部開發。 現在我想要做的是,建立maven項目使用jenkinsNexus Repository Manger Oss。 我可以在沒有Nexus Repository Manger Oss的情況下構建我的項目。

注:我正在使用父母pom,因爲我必須分項目。

波紋管是我遵循的步驟

  • 安裝Nexus Repository Manger Oss。它運行起來
    這裏是屏幕排序 Nexus repository is up and running

  • 在關係倉庫

    安裝ojdbc5罐子

enter image description here

  • 作出必要的.m2目錄下文件Setting.xml的變化文件夾

這裏的setting.xml

<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"> 

    <mirrors> 
     <mirror> 
     <!--This sends everything else to /public --> 
      <id>nexus</id> 
      <mirrorOf>*</mirrorOf> 
      <url>http://localhost:8081/nexus/content/groups/public</url> 
     </mirror> 
    </mirrors> 

    <activeProfiles> 
     <!--make the profile active all the time --> 
     <activeProfile>nexus</activeProfile> 
    </activeProfiles> 

    <profiles> 
     <profile> 
      <id>nexus</id> 
      <repositories> 
      <repository> 
      <id>central</id> 
      <url>http://maven.apache.org</url> 
      <releases><enabled>true</enabled></releases> 
      <snapshots><enabled>true</enabled></snapshots> 
      </repository> 
      </repositories> 

      <pluginRepositories> 
       <pluginRepository> 
        <id>central</id> 
        <url>http://maven.apache.org</url> 
        <releases><enabled>true</enabled></releases> 
        <snapshots><enabled>true</enabled></snapshots> 
       </pluginRepository> 
      </pluginRepositories> 
     </profile> 
    </profiles> 

    <servers> 
     <server> 
     <id>releases</id> 
     <username>deployment</username> 
     <password>deployment123</password> 
     </server> 
     <server> 
     <id>snapshots</id> 
     <username>deployment</username> 
     <password>deployment123</password> 
     </server> 
    </servers> 

</settings> 
  • 加關係庫的細節我pom.xml

父內容pom.xml內容

<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>parent</groupId> 
 
    <artifactId>A</artifactId> 
 
    <packaging>pom</packaging> 
 
    <version>0.0.1-SNAPSHOT</version> 
 
    <name>Maven Webapp</name> 
 
    <!--url>http://maven.apache.org</url--> 
 

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

 

 

 
    <dependencies> 
 
    <dependency> 
 
     <groupId>com.oracle</groupId> 
 
     <artifactId>ojdbc5</artifactId> 
 
     <version>11.2.0.1</version> 
 
    </dependency> 
 
    </dependencies> 
 

 
    <modules> 
 
    <module>subModule1</module> 
 
    <module>subModule2</module> 
 
    </modules> 
 
</project>

subModule1的pom.xml

<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.a</groupId> 
 
    <artifactId>a</artifactId> 
 
    <packaging>war</packaging> 
 
    <version>1.0-SNAPSHOT</version> 
 
    <name>Maven Webapp</name> 
 

 
    <distributionManagement> 
 
    <repository> 
 
     <id>releases</id> 
 
     <!-- CHANGE HERE by your team nexus server --> 
 
     <url>http://localhost:8081/nexus/content/repositories/thirdparty/</url> 
 
    </repository> 
 
    <snapshotRepository> 
 
     <id>snapshots</id> 
 
     <!-- CHANGE HERE by your team nexus server --> 
 
     <url>http://localhost:8081/nexus/content/repositories/snapshots/</url> 
 
    </snapshotRepository> 
 
    </distributionManagement> 
 

 

 
    <dependencies> 
 

 
    // dependecies are defined here 
 
    <dependencies>

在subModule1和subModule2我已經添加了distributionManagement部分。

但是當我建立我的項目獲取波紋管錯誤。

[錯誤]未能就項目submodule1執行目標:無法 項目submodule1解決依賴關係:戰爭:1.0快照:失敗 找到com.oracle:ojdbc5:jar:11.2.0。1 https://repo.maven.apache.org/maven2當地 庫被緩存,分辨率將不會被重新嘗試,直到中央的更新 間隔已過或更新強制 - > [說明1]

我理解錯誤導致,因爲com.oracle:ojdbc5:jar:11.2.0.1 jar依賴不能解決。

但我很驚訝爲什麼它不從我的本地連接庫中選取它。

我是否錯過了任何配置,或者我是否以錯誤的方式進行操作?

如何爲我的項目使用本地連接庫?

回答

0

在您的settings.xml中,通常在您的〜/ .m2 /目錄中,您需要指定您的本地Nexus。默認情況下,您只會獲得Maven中心。

<profile> 
     <id>local</id> 
     <repositories> 
      <repository> 
       <id>nexus</id> 
       <name>libs-release</name> 
       <url>http://url to your local Nexus/artifactory/libs-release</url> 
      </repository> 
     </repositories> 
</profile> 

您可以根據需要添加任意數量的存儲元素。

確保正確的配置文件是活動的,在你的settings.xml

<activeProfiles> 
    <activeProfile>local</activeProfile> 
    </activeProfiles> 

你也將留下你的〜/ .m2目錄/庫/ COM/ORACLE存根的底部...夾。我總是使用rm -r〜/ .m2/repository/com/oracle來強制它從遠程倉庫下載。

0

您的settings.xml未正確覆蓋中央存儲庫配置。正確的設置可以在documentation找到。

還有example projects可供使用,準備就緒,eval guide包括一步一步的指導。

相關問題