美文网首页我爱编程
【原】maven deploy 到nexus3 Return c

【原】maven deploy 到nexus3 Return c

作者: 曹赫洋 | 来源:发表于2018-04-13 09:53 被阅读0次

    问题背景描述:

    maven 3.5.3
    idea 2081.1
    mexus oss OSS 3.9.0-01

    问题截图

    /Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/heyang/java-work/framework/spring-boot-weds-framework/spring-boot-framework "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=52469:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2018.1 clean package deploy -Dmaven.test.skip=true -e
    [INFO] Error stacktraces are turned on.
    [INFO] Scanning for projects...
    [INFO]                                                                         
    [INFO] ------------------------------------------------------------------------
    [INFO] Building spring-boot-framework 0.0.2.RELEASE
    [INFO] ------------------------------------------------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ parent ---
    [INFO] 
    [INFO] --- maven-source-plugin:3.0.1:jar-no-fork (attach-sources) @ parent ---
    [INFO] 
    [INFO] --- maven-source-plugin:3.0.1:jar-no-fork (attach-sources) @ parent ---
    [INFO] 
    [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ parent ---
    [INFO] Installing /Users/heyang/java-work/framework/spring-boot-weds-framework/spring-boot-framework/pom.xml to /Users/heyang/.m2/repository/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom
    [INFO] 
    [INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ parent ---
    Uploading: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 1.347 s
    [INFO] Finished at: 2018-04-13T09:22:43+08:00
    [INFO] Final Memory: 15M/232M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project parent: Failed to deploy artifacts: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. 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.8.2:deploy (default-deploy) on project parent: Failed to deploy artifacts: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
    Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to deploy artifacts: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.apache.maven.plugin.deploy.DeployMojo.deployProject(DeployMojo.java:284)
        at org.apache.maven.plugin.deploy.DeployMojo.execute(DeployMojo.java:169)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
        ... 21 more
    Caused by: org.apache.maven.artifact.deployer.ArtifactDeploymentException: Failed to deploy artifacts: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:143)
        at org.apache.maven.plugin.deploy.AbstractDeployMojo.deploy(AbstractDeployMojo.java:171)
        at org.apache.maven.plugin.deploy.DeployMojo.deployProject(DeployMojo.java:242)
        ... 24 more
    Caused by: org.eclipse.aether.deployment.DeploymentException: Failed to deploy artifacts: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:317)
        at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:245)
        at org.eclipse.aether.internal.impl.DefaultRepositorySystem.deploy(DefaultRepositorySystem.java:413)
        at org.apache.maven.artifact.deployer.DefaultArtifactDeployer.deploy(DefaultArtifactDeployer.java:139)
        ... 26 more
    Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact spring-boot-weds-framework:parent:pom:0.0.2.RELEASE from/to nexus-releases (http://127.0.0.1:8081/repository/maven-releases/): Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:43)
        at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
        at org.eclipse.aether.connector.basic.BasicRepositoryConnector.put(BasicRepositoryConnector.java:274)
        at org.eclipse.aether.internal.impl.DefaultDeployer.deploy(DefaultDeployer.java:311)
        ... 29 more
    Caused by: org.apache.maven.wagon.TransferFailedException: Failed to transfer file: http://127.0.0.1:8081/repository/maven-releases/spring-boot-weds-framework/parent/0.0.2.RELEASE/parent-0.0.2.RELEASE.pom. Return code is: 401, ReasonPhrase: Unauthorized.
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:627)
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:541)
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:523)
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:517)
        at org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.put(AbstractHttpClientWagon.java:497)
        at org.eclipse.aether.transport.wagon.WagonTransporter$PutTaskRunner.run(WagonTransporter.java:644)
        at org.eclipse.aether.transport.wagon.WagonTransporter.execute(WagonTransporter.java:427)
        at org.eclipse.aether.transport.wagon.WagonTransporter.put(WagonTransporter.java:410)
        at org.eclipse.aether.connector.basic.BasicRepositoryConnector$PutTaskRunner.runTask(BasicRepositoryConnector.java:510)
        at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:350)
        ... 31 more
    [ERROR] 
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
    
    Process finished with exit code 1
    
    

    注意到

    774DA018-C97A-4C35-987F-A17686EF7F8F.png

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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>spring-boot-weds-framework</groupId>
        <artifactId>parent</artifactId>
        <version>0.0.2.RELEASE</version>
        <packaging>pom</packaging>
        <name>spring-boot-framework</name>
        <description>spring-boot-weds-framework parent  for Spring Boot</description>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.8.RELEASE</version>
            <relativePath /> <!-- lookup parent from repository -->
        </parent>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <spring.boot.version>1.5.8.RELEASE</spring.boot.version>
            <com.google.guava.version>19.0</com.google.guava.version>
            <springfox.version>2.5.0</springfox.version>
            <pagehelper.version>4.2.1</pagehelper.version>
            <javax.ws.rs-api.version>2.0</javax.ws.rs-api.version>
            <org.apache.poi.version>3.10-beta2</org.apache.poi.version>
            <jsch.version>0.1.46</jsch.version>
            <commons-lang3.verison>3.3.2</commons-lang3.verison>
            <commons-beanutils.version>1.8.3</commons-beanutils.version>
            <javax.mail.version>1.4.1</javax.mail.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-log4j2</artifactId>
            </dependency>
            <!--<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> 
                <optional>true</optional> </dependency> -->
        </dependencies>
        <repositories>
            <repository>
                <id>nexus</id>
                <name>Nexus Repository</name>
                <url>http://127.0.0.1:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>nexus</id>
                <name>Nexus Plugin Repository</name>
                <url>http://127.0.0.1:8081/repository/maven-public/</url>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
                <releases>
                    <enabled>true</enabled>
                </releases>
            </pluginRepository>
        </pluginRepositories>
        <distributionManagement>
            <repository>
                <id>nexus-releases</id>
                <name>Nexus Release Repository</name>
                <url>http://127.0.0.1:8081/repository/maven-releases/</url>
            </repository>
            <snapshotRepository>
                <id>nexus-snapshots</id>
                <name>Nexus Snapshot Repository</name>
                <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>
            </snapshotRepository>
        </distributionManagement>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
    
                <plugin>
                    <!-- 打包插件 -->
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <!--<configuration>-->
                        <!--<useUniqueVersions>false</useUniqueVersions>-->
                    <!--</configuration>-->
                </plugin>
                <!-- 源码插件 目前用于发布jar包到内网的时候连源码一起 -->
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>3.0.1</version>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <phase>package</phase>
                            <goals>
                                <goal>jar-no-fork</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
        </build>
    </project>
    

    maven setting.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
    <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>/Users/heyang/repository</localRepository>
      </pluginGroups>
      <proxies>
      </proxies>
      <servers>
      <server>
        <id>nexus-releases</id>
        <username>admin</username>
        <password>admin123</password>
      </server>
      <server>
        <id>nexus-snapshots</id>
        <username>admin</username>
        <password>admin123</password>
      </server>
        <!-- <server>
          <id>thirdparty</id>
          <username>admin</username>
          <password>admin123</password>
        </server> -->
      </servers>
      <mirrors>
        <mirror>
          <id>nexus</id>
          <name>nexus Mirror,3rd party,chenshu repository</name>
          <url>http://localhost:8081/repository/maven-public/</url>
          <mirrorOf>*</mirrorOf>
        </mirror>
      </mirrors>
      <profiles>
        <profile>
          <id>jdk1.8</id>
          <activation>
            <activeByDefault>true</activeByDefault>
            <jdk>1.8</jdk>
          </activation>
          <properties>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
          </properties>
          <repositories>
            <repository>
              <id>maven-public</id>
              <url>http://localhost:8081/repository/maven-public/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
              </snapshots>
            </repository>
          </repositories>
        </profile>
      </profiles>
    </settings>
    

    关于配置文件里的关键点就不在此赘述了,网上一堆。

    问题排查过程:

    1、由于笔者是通过nexus oss2 升级到 nexus oo3的,升级之后,对于nexus oo3的在线配置以及setting.xml 和pom.xml的配置上区别并不到,需要注意的点是:相对于2,3的url变得更简单了,在修改的时候这里是个关键点。
    2、笔者反复对比了setting.xml 和pom.xml之后,发现并没有问题,这里陷入了一个误区,由于提示信息指向说明的是 ReasonPhrase: Unauthorized,便一直在排查认证相关配置的问题。
    3、经过排查一直没有找到问题,笔者纠结好久之后想到,何不到maven的目录直接mvn depploy 试试,一尝试,还真ok了。
    4、问题回归,为何在idea 里执行maven命令就不可以呢?很明显应该是maven的配置文件出现了问题


    1523583869597.jpg

    这是idea配置maven的地方,一定是这里出了问题,乍看没问题


    1523583937446.jpg
    执行了mvn -v 查看之后仔细看发现,mvn的版本并不一样。
    5.发现只有图片中的地方没改过,问题一定是出现这里
    1523584008290.jpg
    修改
    1523584112702.jpg

    再次在idea中执行命令:


    1523584175306.jpg
    问题解决。

    思考与心得:

    1.问题的研发一定是多样的,整个排查过程中前期将问题指向Unauthorized并没有问题,但是排查完之后耽误时间过长,应该在反复对照两次,确定setting.xml 和pom.xml没问题之后,迅速的先进行其他可能的尝试。
    2.对于Unauthorized的问题,应该优先考虑到关于auth的配置不生效可能出现问题,从而先到项目目录执行mvn deploy进行尝试,如果ok,咋寻找idea关于maven配置地方的问题。

    相关文章

      网友评论

        本文标题:【原】maven deploy 到nexus3 Return c

        本文链接:https://www.haomeiwen.com/subject/lvgqkftx.html