Maven私服(Nexus)的簡介和使用


https://blog.csdn.net/javanbme/article/details/113345312

私服安裝https://blog.csdn.net/javanbme/article/details/113336338
 
1. 倉庫介紹

1)maven-central:maven中央庫,默認從https://repo1.maven.org/maven2/拉取jar
2)maven-releases:私庫發行版jar
3)maven-snapshots:私庫快照(調試版本)jar
4)maven-public:倉庫分組,把上面三個倉庫組合在一起對外提供服務,在本地maven基礎配settings.xml中使用。
 
Nexus倉庫類型介紹
默認安裝有以下這幾個倉庫,在控制台也可以修改遠程倉庫的地址,第三方倉庫等。
hosted(宿主倉庫庫) :存放本公司開發的jar包(正式版本、測試版本)proxy(代理倉庫):代理中央倉庫、Apache下測試版本的jar包group(組倉庫):使用時連接組倉庫,包含Hosted(宿主倉庫)和Proxy(代理倉庫)

找依賴包的流程: 首先在本地倉庫中找,如果沒命中,那么就找遠程私服;遠程私服的查找規則同樣是先找host屬性的私有庫,然后再去找proxy屬性的遠程倉庫;可以配置多個proxy;
 
2. 倉庫介紹、創建

2.1 創建jCenter阿里雲倉庫http://maven.aliyun.com/nexus/content/groups/public/


2.2 maven中央倉庫(無需修改)https://repo1.maven.org/maven2/


2.3 將Jcenter倉庫移至maven-public 組倉庫

 
3. 配置依賴3.1 添加maven倉庫鏡像創建好組倉庫之后,修改setting.xml文件,添加maven倉庫鏡像,如下
<mirrors>    <mirror>      <id>nexus-myself</id>      <!--*指的是訪問任何倉庫都使用我們的私服-->      <mirrorOf>*</mirrorOf>      <name>Nexus myself</name>      <url>http://121.4.207.231:8081/repository/maven-public/</url>    </mirror></mirrors>3.2 全局配置下載依賴(即項目pom無需配置)在maven的setting.xml文件中配置私服配置,這種方式配置后所有本地使用該配置的maven項目的pom文件都無需配置私服下載相關配置。
<profiles>  <profile>     <id>mycof</id>        <repositories>        <!-- 私有庫地址-->          <repository>          <id>nexus</id>          <url>http://121.4.207.231:8081/repository/maven-public/</url>          <releases>            <enabled>true</enabled>          </releases>          <snapshots>            <enabled>true</enabled>          </snapshots>        </repository>      </repositories>            <pluginRepositories>        <!--插件庫地址-->        <pluginRepository>          <id>nexus</id>          <url>http://121.4.207.231:8081/repository/maven-public/</url>          <releases>            <enabled>true</enabled>          </releases>          <snapshots>            <enabled>true</enabled>           </snapshots>        </pluginRepository>      </pluginRepositories>    </profile></profiles>3.3 激活使用上面的配置<!--激活profile--><activeProfiles>  <activeProfile>mycof</activeProfile></activeProfiles>3.4 單獨項目下載依賴(即項目pom文件中配置) (擴展)這種配置是修改單個項目的pom文件,無需修改maven的setting配置
<repositories>  <repository>    <id>nexus</id>    <url>http://121.4.207.231:8081/repository/maven-public/</url>    <releases>      <enabled>true</enabled>    </releases>    <snapshots>    <enabled>true</enabled>    </snapshots>  </repository></repositories> 
4. 上傳Jar包到私服對於中央倉庫沒有的jar包,需要我們自己將jar包發布到私服中去,其中jar包主要分為兩類,
一類是本地自己開發供給項目組其余同事使用,這種直接配置項目的pom文件和maven的setting文件,之后deploy發布即可發布到;
另一類是第三方jar包,可以直接使用web頁面上傳並設置對應GAV即可;
 
4.1 本地maven開發的項目上傳配置maven的setting文件配置
<servers>    <server>          <id>maven-releases</id>          <username>admin</username>          <password>admin123</password>      </server>      <server>          <id>maven-snapshots</id>          <username>admin</username>          <password>admin123</password>      </server>  </servers>項目中的pom文件配置
<distributionManagement>    <repository>        <id>maven-releases</id>        <name>Nexus Release Repository</name>        <url>http://121.4.207.231:8081/repository/maven-releases/</url>    </repository>    <snapshotRepository>        <id>maven-snapshots</id>        <name>Nexus Snapshot Repository</name>        <url>http://121.4.207.231:8081/repository/maven-snapshots/</url>    </snapshotRepository></distributionManagement> <profiles>    <profile>        <id>java8-doclint-disabled</id>        <activation>            <jdk>1.8</jdk>        </activation>        <properties>            <javadoc.opts>-Xdoclint:none</javadoc.opts>        </properties>    </profile></profiles> <build>    <plugins>        <plugin>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-maven-plugin</artifactId>        </plugin>        <!--編譯插件-->        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <configuration>                <source>1.8</source>                <target>1.8</target>                <encoding>UTF-8</encoding>                <!--解決JDK7以后,帶com.sun.*的類庫將不會被支持-->                <!--<compilerArgument>-XDignore.symbol.file</compilerArgument>-->                <compilerArguments>                    <bootclasspath>${java.home}/lib/rt.jar:${java.home}/lib/jce.jar</bootclasspath>                </compilerArguments>            </configuration>            <artifactId>maven-compiler-plugin</artifactId>            <version>3.5.1</version>        </plugin>        <!-- 生成javadoc文檔包的插件 -->        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-javadoc-plugin</artifactId>            <version>2.9</version>            <executions>                <execution>                    <id>attach-javadocs</id>                    <goals>                        <goal>jar</goal>                    </goals>                    <configuration>                        <additionalparam>${javadoc.opts}</additionalparam>                    </configuration>                </execution>            </executions>        </plugin>        <!-- 生成sources源碼包的插件 -->        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-source-plugin</artifactId>            <version>2.4</version>            <configuration>                <attach>true</attach>            </configuration>            <executions>                <execution>                    <phase>package</phase>                    <goals>                        <goal>jar-no-fork</goal>                    </goals>                </execution>            </executions>        </plugin>        <!--部署jar包到遠程倉庫-->        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-deploy-plugin</artifactId>            <version>2.7</version>        </plugin>    </plugins></build>  執行maven的deploy命令
  ps: 第一次初始化有點慢 耐心等待  deploy成功之后查看依賴


  Release倉庫默認不支持重復發布 如果項目中使用的是SNAPSHOT后綴 即不需要配置  快照版本會根據上傳時間檢測新的快照版本


 
4.2 第三方jar包上傳



 
5. 引入私服Jar包

 
 ————————————————版權聲明:本文為CSDN博主「javanbme」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。原文鏈接:https://blog.csdn.net/javanbme/article/details/113345312


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM