java 9 unnamed module reads package [X] from both … while debugging (with IntelliJ)

旧街凉风 提交于 2019-12-05 15:27:25

I had the same 100+ multititude of "ERROR: The unnamed module reads package javax.xml from both xml.apis and java.xml" in my Java 9 IntelliJ project too.

Except I would get them whenever I tried to run unit tests in IntelliJ. Everything worked perfectly building and testing with maven from the command line; just like you.

I was able to make my errors go away by...

1) Removing the following from the top-level pom of a multi-module project...

<dependency>
    <groupId>xml-apis</groupId>
    <artifactId>xml-apis</artifactId>
    <version>1.4.01</version>
</dependency>  
...
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>${javaee.api.version}</version>
    <scope>provided</scope>
</dependency>

2) Right clicking the top-level pom in IntelliJ's project navigator, then select "Maven - Reimport"

3) Doing "Build -> Build module [myModule]" from the IntelliJ menu.

Just work out which maven artifacts contain the packages listed in your 100+"ERROR" messages. Then comment them out. Reimport. Then "Build module" from the menu. That worked for me anyway.

The artifacts I removed from the pom were copy/pasted in there speculatively from another project I used as a template. But luckily I don't need any of them.

This is a known IDEA bug. Please vote for https://youtrack.jetbrains.com/issue/IDEA-171320

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!