gpt4 book ai didi

java - Maven : No compile errors but still cant find symbol

转载 作者:行者123 更新时间:2023-12-02 11:49:29 30 4
gpt4 key购买 nike

我在 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 中没有看到任何编译错误。我正在使用 eclipse mars。

如何才能成功构建?

最佳答案

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

test
This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

另请检查此 documentation for Maven Dependency Scope

关于java - Maven : No compile errors but still cant find symbol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47982735/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com