【问题标题】:Maven : No compile errors but still cant find symbolMaven:没有编译错误但仍然找不到符号
【发布时间】:2017-12-26 19:09:26
【问题描述】:

我在 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>

我知道范围是测试

&lt;scope&gt;test&lt;/scope&gt;

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

如何才能成功构建?

【问题讨论】:

  • 你的班级在src/test/java吗?
  • 在构建过程中应该不重要:当然重要。范围测试的依赖项用于编译测试类,而不是生产类。 Eclipse 无法进行区分,这就是为什么您在 Eclipse 中没有问题。

标签: java eclipse maven


【解决方案1】:

尝试删除 test 部分。或者使用 compile 范围。

测试
该范围表示该依赖不是应用正常使用所必需的,仅适用于测试编译和执行阶段。

也可以查看documentation for Maven Dependency Scope

【讨论】:

  • 很高兴它有帮助!
  • 这是由于 Eclipse 的限制,因此无法 100% 模拟正确的 maven 行为。
猜你喜欢
  • 2020-05-23
  • 2015-11-06
  • 2019-05-31
  • 1970-01-01
  • 1970-01-01
  • 2016-02-17
  • 1970-01-01
  • 2023-03-30
  • 2011-04-23
相关资源
最近更新 更多