Eclipse IDE版本2019-09 R(4.13.0)无法识别Maven依赖项

时间:2019-11-10 05:31:21

标签: java eclipse maven

我的Eclipse版本

Eclipse IDE for Enterprise Java Developers.
Version: 2019-09 R (4.13.0)
Build id: 20190917-1200
OS: Windows 10, v.10.0, x86_64 / win32
Java version: 13.0.1

我创建一个具有pom.xml

的Java应用程序
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>junit5_sample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0-M1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.0-M1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.10</version>
            </plugin>            
        </plugins>
    </build>
</project>

样品分类

package com.sample.junit5;

import static org.junit.jupiter.api.Assertions.fail;

public class StringTest {

    @Test
    void test() {
        fail("Not yet implemented");
    }

}

但是Eclipse IDE版本2019-09 R(4.13.0)无法识别Maven依赖项

enter image description here

如何解决?

1 个答案:

答案 0 :(得分:1)

Junit依赖项在pom.xml的测试范围中声明(如预期的那样),因此您的测试类必须位于test文件夹中:src / test / java而不是src / main / java。