2017-04-22 120 views
0

我正在用java 9(build 9-ea + 165)构建一个使用maven 3.3.9的项目。测试运行并且构建成功。如何在JDK 9中为IntelliJ添加测试依赖关系?

但是, IntelliJ Idea 2017.1.2抱怨并且不会通过消息'该模块在其需求中没有模块'junit.jupiter.api'来编译/运行测试。

如何为IntelliJ添加此项? 是否有必要?

截图: Screenshot from editor in IntelliJ.

项目结构: Project structure

从POM:

<dependencies> 
    <!-- testing --> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-all</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.junit.jupiter</groupId> 
     <artifactId>junit-jupiter-api</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-core</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>9</source> 
        <target>9</target> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.junit.platform</groupId> 
         <artifactId>junit-platform-surefire-provider</artifactId> 
         <version>1.0.0-M4</version> 
        </dependency> 
        <dependency> 
         <groupId>org.junit.vintage</groupId> 
         <artifactId>junit-vintage-engine</artifactId> 
         <version>4.12.0-M4</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
     </plugin> 
     <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 
+0

请分享消息的确切消息或屏幕截图,还有什么测试依赖关系是否使用? – nullpointer

+0

你用java 8试过吗?你的来源可能吗?也许只是为了检查它是否修复了测试中的依赖关系,即使它不能编译和运行你的代码 –

+0

你是否检查过你的maven缓存中有相关的jar包?通常〜/ .m2/repository/... –

回答

0

这有可能是你的项目结构不再有效。您可以尝试检查包含您的测试的文件夹是否为您的实际测试文件夹:

  1. 按下[Ctrl] [Alt] [Shift] [S]打开Project Structure。
  2. 打开“模块”
  3. 打开“源标签”包含测试
  4. 你的文件夹应被标记为“测试”(图标为绿色)
+0

项目结构良好,Joost Verbraeken。文件夹src/main/java是蓝色的,标记为源文件夹,src/test/java为绿色并标记为测试源文件夹... – TEJacobsen

0

有几个选项

首先,您可能尚未将项目正确导入到IntelliJ中。在这种情况下,要做的最快的事情往往是简单地关闭项目,从源目录(.idea目录和任何*.i?l文件)中删除intellij文件,并使用open选项重新打开相应的根文件夹文件(如果它给你的该选项,选择创建一个新项目并删除旧项目)。

第二种选择是你已经正确地打开了项目,但你没有重新导入它,因为改变了pom,并且你没有启用自动导入,并且忽略了要求你重新加载的通知。在这种情况下,只需打开maven窗口(通常从屏幕右侧的水平按钮),然后点击maven窗口左上角的重新导入按钮。

第三个选项是吹走你的缓存。这很容易从文件菜单完成。

可能有其他的。我会从头开始。

+0

首先:我关闭了项目。 idea文件夹并删除了任何* .i?l文件。使用项目的根目录导入项目更多......但没有雪茄:(......第二和第三:我刷新了所有Maven项目,并且尝试使我的缓存无效并重新启动IntelliJ,但仍然没有雪茄...... :(我不认为第二个和第三个选项应该以任何方式提供帮助,因为我无法首先导入项目... – TEJacobsen

相关问题