這是第一次使用 nexus 私服上傳本身的 jar 包到倉庫裏,各類不懂各類搜索,百度完了又谷歌,終於大概瞭解了個流程。apache
大體上能夠分爲 mvn deploy 和 mvn deploy:deploy-file。bash
mvn deploy:deploy-file -DgroupId=com.jpay -DartifactId=common-payment-sdk -Dversion=0.0.1-SNAPSHOT -Dpackaging=jar -Dfile=./target/common-payment-sdk-0.0.1.jar -Durl=http://10.100.86.153:8081/repository/maven-snapshots/ -DrepositoryId=nexus-snapshots
mvn deploy:deploy-file -DgroupId=com.jpay -DartifactId=common-payment-sdk -Dversion=0.0.1 -Dpackaging=jar -Dfile=./target/common-payment-sdk-0.0.3.jar -Durl=http://10.100.86.153:8081/repository/maven-releases/ -DrepositoryId=nexus-release
複製代碼
如今來講說我所遇到的問題,如今拿 jpay 這個整合支付來測試一下,常常一番努力以後,終於把 jar 包上傳到 nexus 裏了,這時想着應該要事成了,把本地 ~/.m2/repository/com/jpay 這個依賴刪除,試試看有沒有從私服上 download 依賴包,發現 mvn install 時徹底沒有 download 的步驟,沒理由啊~app
因而指定一下私服地址,在 pom.xml 裏增長:maven
<repositories>
<repository>
<id>nexus</id>
<name>nexus</name>
<url>http://10.100.86.153:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
複製代碼
再執行一次 mvn install,依然沒有反應,沒有 download,而後編譯錯誤提示找不到 jpay 依賴包。這時我再想,會不會是應該打包的時候把全部的第三方依賴都打包進去呢?因而,我又在 jpay 的 pom.xml 裏增長了個插件配置:測試
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<!-- 此處指定main方法入口的class -->
<mainClass></mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>
複製代碼
再次打包,本來160K 的 jar 包變成了 26M 了,再次試試打包項目,終於經過了。url
因而我又試着去看看別人的 jar 包會不會也把全部依賴打包進去呢?進去 ~/.m2/repository 找別人的包一看,都好小哦,再看看 pom.xml 一看,不少 dependency 在裏面,我打開 nexus 進去找到我上傳的包看看 pom.xml 發現只有簡單的幾行:spa
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jpay</groupId>
<artifactId>payment-sdk</artifactId>
<version>0.0.1</version>
</project>
複製代碼
我插~~~問題就是出在這裏,確定是我打包的姿式不對,因而我在 jpay 的 pom.xml 里加上分發管理配置:插件
<distributionManagement>
<repository>
<id>nexus-release</id>
<name>Nexus Releases Repository</name>
<url>http://10.100.86.153:8081/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshots Repository</name>
<uniqueVersion>false</uniqueVersion>
<layout>legacy</layout>
<url>http://10.100.86.153:8081/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
複製代碼
而後 mvn deploy 執行發佈,看見有上傳到 nexus success 成功的字樣,去 nexus 查看一下 pom.xml 文件,終於看到有 dependency 在裏面了。code
刪除本地 ~/.m2/repository/com/jpay 再打包一次項目,終於能從私服上拉取到依賴包了。xml
事到這裏暫告一段落,改天有空再肯定一下 deploy-file 上傳是否是應該用 mvn package 後連同 pom 一塊上傳。