maven项目新检出后不编译爬坑记 及 mvn clean package报错 WagonTransporterFactory: java.util.NoSuchElementException 异常【我】

从 SVN 新检出一个 maven 项目,配置好后,发现项目无法编译 (只有一个 test 包中的代码显示编译报错,其他所有包中的代码都不编译,也不报错)

 

先注释掉报错的 test 包中的所有内容,

用 Eclipse 自带的 maven 执行 clean 命令,失败,异常信息为:

Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin🏺2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to alimaven (http://maven.aliyun.com/nexus/content/groups/public/): Cannot access http://maven.aliyun.com/nexus/content/groups/public/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access http://maven.aliyun.com/nexus/content/groups/public/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
[ERROR]       role: org.apache.maven.wagon.Wagon

 

参考了如下文章:

------------------ 转载开始 ---------------

mvn clean package 报错 WagonTransporterFactory: java.util.NoSuchElementException

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Min_Monk/article/details/97271854

在 eclipse 中执行 clean package 指令报错,错误信息如下:

  1. [INFO] Scanning for projects...
  2. [INFO]
  3. [INFO] --------------------------< com.demo:ws-demo >--------------------------
  4. [INFO] Building ws-demo 0.0.1-SNAPSHOT
  5. [INFO] -------------------------------[bundle]-------------------------------
  6. [INFO] ------------------------------------------------------------------------
  7. [INFO] BUILD FAILURE
  8. [INFO] ------------------------------------------------------------------------
  9. [INFO] Total time: 0.668 s
  10. [INFO] Finished at: 2019-07-25T16:04:20+08:00
  11. [INFO] ------------------------------------------------------------------------
  12. [ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin🏺3.1.0: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:3.1.0 from/to public (http://******************.com/nexus/content/groups/public/): Cannot access http://******************.com/nexus/content/groups/public/ with type default using the available connector factories: BasicRepositoryConnectorFactory: Cannot access http://******************.com/nexus/content/groups/public/ using the registered transporter factories: WagonTransporterFactory: java.util.NoSuchElementException
  13. [ERROR] role: org.apache.maven.wagon.Wagon
  14. [ERROR] roleHint: http
  15. [ERROR] -> [Help 1]
  16. [ERROR]
  17. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  18. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  19. [ERROR]
  20. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  21. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
  22.  

网上有很多解决办法,分别如下:

  1.  由于 maven 默认的下载服务器在国外,网络不好下载不好 jar 包,让修改 maven_home/conf 目录下的 setting 文件,增加阿里的下载镜像地址,然后重新下载插件;
  2.  删除插件在本地仓库中的目录,重新下载,不停的尝试,直到可行为止
  3. 等等等。。。。。。

小编在尝试上面的两种方式之后,最终的解决办法:

在 cmd 窗口进入到项目目录下,执行指令 mvn clean package,然后就BUILD SUCCESS,试 100 次成功 100 次,回头再到 eclipse 中执行,也BUILD SUCCESS 了

个种原因我就不是很清楚,只是不再相信 eclipse 的这些插件了。还是老老实实在 cmd 窗口敲命令

 

------------------ 转载结束 --------------

 

想到可能是 Eclipse 自带的 maven 插件不太好用,于是,用本地安装的 maven,在项目目录下,打开黑窗口,执行 clean ,成功了,没有报错,进而想到,可以在 Eclipse 中使用本地的 maven,方法如下

 

 

本地安装的 maven 目录:

 

 也就是填到 bin 的上级目录即可。

 

再次用 Eclipse 执行 clean ,通过了,没有报错。

-------------------------------------------------

 

但是项目中的其他包中的代码还是不编译,而且在 Eclipse 中的执行 maven 的 compile 指令

方法为,在项目上右键,run as ——maven build ...

 

 虽然执行成功,但是 日志显示 没有可编译的文件。

 

。。。

各种百度、测试,最终把目标转移到项目下的  .classpath 文件

 

 此文件需要在 Eclipse 的 Navigator 视图中才能看到,或者直接到项目目录中去找:

 

 

经过和一个本地正常的 maven 项目的 .classpath 文件比较

正常项目的 .classpath 文件:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="test" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

 

 异常项目的 文件:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry excluding="**/test/" kind="src" output="target/classes" path="src/main/java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry exported="true" kind="lib" path="G:/ty/oracle/jdbc_qudong/ojdbc14-10.2.0.4.0.jar">
        <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" output="target/test-classes" path="src/test/java">
        <attributes>
            <attribute name="test" value="true"/>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="output" path="target/classes"/>
</classpath>

 

发现,其在 主要源文件目录 src/main/java 的相关配置中,前面多了一个  excluding="**/test/"

 

 我靠,这个不正是项目中唯一被会被编译的 包的路径嘛,

想到这,直接把   excluding="**/test/" 这个 删除,保存,然后重启 Eclipse,所有包都编译了,故障排除。

 

---------------

启发:

刚从 svn 检出的项目,如果经过各种排查后还是有问题,尤其是 不编译 类 问题,可以查看一下项目下的 .classpath 文件,这个文件第一次检出项目时,会从 svn 上更新下来,然后随着本地的操作会发生变化。

如果 svn 上被提交的源 .classpath 文件就有问题,或者由于检出后本地的某些操作,也可能导致  这个文件出现异常,最终结果就是导致项目的构建发生各种问题。

 

排查其是否有问题的方法

1、可以在本地新建一个好用的 maven 项目,然后用其自动生成的 .classpath 文件,和故障项目的 文件比对。

2、可以直接使用上面文章中的例子

3、可以和同事好用的项目中的文件比对。