Maven:没有编译错误但仍无法找到符号

时间:2017-12-26 19:09:26

标签: java eclipse maven

我在eclipse中有一个非常基本的maven项目。我用一些新的依赖项更新了pom,之后我就无法做到了

mvn clean install

mvn compile

每次我得到

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project commons: Compilation failure: Compilation failure:
[ERROR] /path/to/my/class:[5,40] package org.springframework.test.context does not exist
[ERROR] /path/to/my/class:[8,2] cannot find symbol
[ERROR] symbol: class ActiveProfiles

但我在我的pom中有所需的依赖性,即

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>5.0.0.RELEASE</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
            </exclusion>
            <exclusion>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

我知道范围是测试

<scope>test</scope>

但在构建期间这应该无关紧要?最重要的是,我在IDE中看不到任何编译错误。我正在使用日食火星。

我如何成功建立?

1 个答案:

答案 0 :(得分:1)

尝试删除&lt;范围&gt;测试&lt; / scope&gt; 部分。或者使用编译范围。

  

<强>测试
  此范围表示正常使用应用程序不需要依赖关系,并且仅适用于测试编译和执行阶段。

同时检查此documentation for Maven Dependency Scope