Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何向JDK 9 for IntelliJ中的模块添加测试依赖项?_Java_Maven_Intellij Idea_Java 9 - Fatal编程技术网

Java 如何向JDK 9 for IntelliJ中的模块添加测试依赖项?

Java 如何向JDK 9 for IntelliJ中的模块添加测试依赖项?,java,maven,intellij-idea,java-9,Java,Maven,Intellij Idea,Java 9,我正在使用Java9(Build9-ea+165)用maven 3.3.9构建一个项目。测试运行和构建成功 不过。IntelliJ Idea 2017.1.2正在抱怨,不会编译/运行带有消息“模块的需求中没有模块‘junit.jupiter.api’的测试 如何为IntelliJ添加此项? 有必要吗 截图: 项目结构: 来自pom: <dependencies> <!-- testing --> <dependency> &

我正在使用Java9(Build9-ea+165)用maven 3.3.9构建一个项目。测试运行和构建成功

不过。IntelliJ Idea 2017.1.2正在抱怨,不会编译/运行带有消息“模块的需求中没有模块‘junit.jupiter.api’的测试

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

截图:

项目结构:

来自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>

org.hamcrest
汉克雷斯特酒店
测试
org.junit.jupiter
JUnitJupiter api
测试
朱尼特
朱尼特
测试
org.mockito
莫基托磁芯
测试
maven编译器插件
3.6.1
9
9
真的
真的
maven surefire插件
2.19
org.junit.platform
junit平台surefire提供程序
1.0.0-M4
org.junit.vintage
朱尼特老式发动机
4.12.0-M4
maven编译器插件
maven surefire插件

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

  • 按[Ctrl][Alt][Shift][S]打开项目结构
  • 打开“模块”
  • 打开“源选项卡”
  • 包含测试的文件夹应标记为“测试”(图标为绿色)

  • 有几个选择

    首先,您可能没有将项目正确导入IntelliJ。在这种情况下,最快的方法通常是关闭项目,从源目录(
    .idea
    目录和任何
    *.i?l
    文件)中删除intellij文件,然后使用
    打开
    选项重新打开相应的根pom文件(如果提供了选项,请选择创建新项目并删除旧项目)

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

    第三个选择是清除缓存。这可以通过“文件”菜单轻松完成


    可能还有其他的。我会从下往上开始。

    项目结构很好,Joost Verbraeken。文件夹src/main/java是蓝色的,标记为源文件夹,src/test/java是绿色的,标记为测试源文件夹……请共享确切的消息或消息的屏幕截图,以及您使用的测试依赖项(如果有的话)是什么您使用java 8进行了尝试?您的源代码是否可以?可能只是为了检查它是否修复了测试中的依赖项,即使它无法编译和运行您的代码。您是否检查了maven缓存中是否有相关JAR?通常是~/.m2/存储库/…您是否可以检查依赖项管理部分中是否有相关条目对于每个LIB,它都有一个ok版本?当IntelliJ运行您的测试时,它可能会在控制台顶部输出它使用的命令——包括类路径。检查一下,看看您需要的JAR是否按照正确的顺序在类路径上。首先:我已经关闭了项目。删除了.idea文件夹并删除了所有的*.I?l file.使用项目的根pom更多地导入了项目…但没有雪茄:(…第二和第三:我已刷新了所有maven项目,并尝试使缓存无效并重新启动IntelliJ,但仍然没有雪茄…:(我不认为第二个和第三个选项会有任何帮助,因为我首先无法导入项目。。。