无法解析 Maven 项目中的 com.sun:tools:0?

Nic*_*hez 6 java selenium intellij-idea maven tools.jar

我最近一直在研究自动化测试。

我现在熟悉了一些工具、框架、依赖项等,例如 Selenium、JUNits、TestNG,它们可以帮助我管理作为 QA 工程师的日常工作。

我经常使用 Selenium 和 TestNG 来构建我的解决方案,以及在最新 JDK 版本 (jdk-15.0.1) 上运行的 IntelliJ IDEA,该版本可在运行 macOs Catalina Version 10.15.7 的 Mac上使用。

我已经为我的项目配置了 mi POM.mxl 文件,从一开始它就在控制台上显示以下错误:

Cannot resolve com.sun:tools:0

我总是忽略这一点,因为我的 IDE 中的项目总是编译并运行,并且因为我从未使用过该依赖项。但现在我正尝试在 Mac 终端的 Maven 支持下运行我的项目,并且由于 sun:tools.jar 依赖项,我不允许编译迄今为止开发的任何工作项目。

我已经阅读了很多关于具有相同 sun:tools:jar 依赖项的类似问题的类似线程,如下所示:

我已经做了所有的事情,但是很多解决方案都是基于在jdk安装目录中找到tools.jar文件。由于我使用的是 JDK 15,因此该依赖项已被删除:

删除:rt.jar 和 tools.jar

以前存储在 lib/rt.jar、lib/tools.jar、lib/dt.jar 和各种其他内部 JAR 文件中的类和资源文件现在以更有效的格式存储在 lib 目录中的特定于实现的文件中。这些文件的格式未指定,如有更改,恕不另行通知。

我附上我在终端上收到的确切错误消息:

 ----------------------< org.example:YelpExercise >----------------------
[INFO] Building YelpExercise 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.737 s
[INFO] Finished at: 2020-11-04T18:59:47-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project YelpExercise: Could not resolve dependencies for project org.example:YelpExercise:jar:1.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:0 at specified path /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home/../lib/tools.jar -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/DependencyResolutionException
Run Code Online (Sandbox Code Playgroud)

Nic*_*hez 7

好吧,经过几个小时甚至几天的研究,我找到了解决方案:

对于 JDK 9 及更高版本,定义 pom.xml 时,每当您要使用包含该子依赖项的依赖项时,都必须排除该子依赖项。就我而言,cobertura 依赖项包括sun.com:tools

我在 pom.xml 文件中编辑的内容:

<!-- https://mvnrepository.com/artifact/net.sourceforge.cobertura/cobertura -->
    <dependency>
        <groupId>net.sourceforge.cobertura</groupId>
        <artifactId>cobertura</artifactId>
        <version>2.1.1</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

对于某些 Maven 依赖项来说,这似乎仍然是一个悬而未决的问题。检查:issues1issues2或 Google 搜索:<dependency_you_are_using> sun tools了解更多信息。