javamaven:packageorg。junit不存在,即使它在pom的依赖项列表中声明。xml
我们得到了这个错误,并没有幸运地搜索了其他SO问题。我们的pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
但我们仍然得到:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project 安卓: Compilation failure: Compilation failure:
[ERROR] /Users/sjain68/zxing/安卓/src/test/java/com/google/zxing/client/安卓/ReverseGeocoderTest.java:[3,17] package org.junit does not exist
请注意,正如这个问题的其他答案所指出的,这个类位于src/test/java
之下
# 1 楼答案
正如你所指出的。。。您的源代码在
src/test/java
中,但此处执行的目标是compiler:compile
,这将用于构建实际的源代码,而不是compiler:testCompile
用于构建测试。关于这两个不同的目标,请参阅maven编译器插件的文档:https://maven.apache.org/plugins/maven-compiler-plugin/我怀疑有什么东西(配置、糟糕的插件等等)正在将src/test/java添加到构建路径中。。。或者更改生成目录。。。不幸的是,我已经有一段时间没有亲自做maven了,但这似乎是不匹配的地方