4

我最近一直在使用测试自动化。

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

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

我已经为我的项目配置了 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
4

1 回答 1

6

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

对于 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>

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

于 2020-11-05T15:18:40.157 回答