1. 程式人生 > >解決,MAVEN

解決,MAVEN

  • eclipse中指定的 setting.xml

<?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">
    <!--本地倉庫位置-->
    <localRepository>D:/.m2/repository</localRepository>
    <offline>false</offline>
    <pluginGroups />
    <proxies />
    <!--設定 Nexus 認證資訊 -->
    <servers>
		<server>
        	<id>releases</id>
        	<username>admin</username>
        	<password>xyz</password>
    	</server>
		<server>
        	<id>snapshots</id>
        	<username>admin</username>
        	<password>xyz</password>
    	</server>
    </servers>
</settings>
  • pom.xml
	<!-- snapshots/releases釋出配置 -->
	<distributionManagement>
		<repository>
			<id>releases</id>
			<url>http://192.168.9.119:8081/nexus/content/repositories/releases</url>
		</repository>
		<snapshotRepository>
			<id>snapshots</id>
			<url>http://192.168.9.119:8081/nexus/content/repositories/snapshots/</url>
		</snapshotRepository>
	</distributionManagement>
  • 上面的配置是沒任何問題。
  • admin許可權是夠的
  • 配置沒出任何問題
  • 報錯資訊
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.388 s
[INFO] Finished at: 2018-11-07T11:24:04+08:00
[INFO] Final Memory: 32M/211M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project eqzh-admin-core: Failed to deploy a
rtifacts: Could not transfer artifact com.eqzh.admin:eqzh-admin-core:jar:1.0-20181107.032404-2 from/to snapshots (http://192.168.9.119:8081/nexus/cont
ent/repositories/snapshots/): Failed to transfer file: http://192.168.9.119:8081/nexus/content/repositories/snapshots/com/eqzh/admin/eqzh-admin-core/1
.0-SNAPSHOT/eqzh-admin-core-1.0-20181107.032404-2.jar. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy
) on project eqzh-admin-core: Failed to deploy artifacts: Could not transfer artifact com.eqzh.admin:eqzh-admin-core:jar:1.0-20181107.032404-2 from/to
 snapshots (http://192.168.9.119:8081/nexus/content/repositories/snapshots/): Failed to transfer file: http://192.168.9.119:8081/nexus/content/reposit
ories/snapshots/com/eqzh/admin/eqzh-admin-core/1.0-SNAPSHOT/eqzh-admin-core-1.0-20181107.032404-2.jar. Return code is: 401, ReasonPhrase: Unauthorized
.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)

關鍵來了

  • depaly.bat
call mvn deploy -X -Dmaven.test.skip=true
call pause

這個指令碼命令本身並沒有問題,問題出在對MAVEN機制不熟悉。

cmd 中呼叫 mvn 命令時,MAVEN預設啟用的是

$M2_HOME/conf/settings.xml

這個路徑下的setting.xml的配置檔案,而不是在ide裡指定的setting.xml的配置檔案

所以,在使用指令碼進行MAVEN操作時,請指定你需要使用的setting.xml檔案路徑,所以

正確的deploy.bat配置

call mvn deploy -X -Dmaven.test.skip=true --setting D:\.m2\settings.xml
call pause

另外值得注意的是

  • 在eclipse中構建,打包,釋出專案時,請使用 Run as --> Maven biuld 來進行MAVEN操作,因為eclipse會為你直接指定,你在eclipse中配置的setting.xml檔案路徑作為--setting的引數。
  • 如圖 在這裡插入圖片描述