解决,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)

关键来了

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

这个脚本命令本身并没有问题,问题出在对MAVEN机制不熟悉。

cmd 中调用 mvn 命令时,MAVEN默认启用的顺序

${MAVEN_HOME}/conf/settings.xml      # MAVEN默认全局配置
${user.home}/.m2/settings.xml        # 用户配置
                      # 优先级:用户配置 > MAVEN默认全局配置

这个路径下的setting.xml的配置文件,而不是在ide里指定的setting.xml的配置文件

所以,在使用脚本进行MAVEN操作时,请指定你需要使用的setting.xml文件路径,所以

正确的deploy.bat配置

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

另外值得注意的是

  • 在eclipse中构建,打包,发布项目时,请使用 Run as --> Maven biuld 来进行MAVEN操作,因为eclipse会为你直接指定,你在eclipse中配置的setting.xml文件路径作为--settings的参数。
  • 如图
    在这里插入图片描述
学生浅薄 望众师指点
原文地址:https://www.cnblogs.com/Nihility/p/14695651.html