spring 启动构建包 org.junit 不存在
spring boot build package org.junit does not exist
我在构建环境中构建 Spring 引导应用程序时收到以下编译错误。但是,当 运行 Junit 在我的机器上本地测试或构建(打包)它时,我没有看到任何错误 -
src/main/java/com/abc/tests/AbcTest.java : package org.junit does
not exist
这是我的 pom.xml -
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
<dependencies>........
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
这是我尝试过但没有成功的步骤 -
1. 在依赖部分中显式依赖 junit 4.12 和 [4.12]。
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
- 使用和不使用插件版本 2.18.1 添加 maven-surefire-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<junitArtifactName> junit:junit:4.12</junitArtifactName>
</configuration>
</plugin>
有没有其他方法可以强制构建过程在 pom.xml 中使用 4.12 junit 版本,而不是选择像 3.8 这样的旧版本?
谢谢
您已将测试放在 main/java
而不是 test/java
中:src/main/java/com/abc/tests/AbcTest.java
Junit 依赖项具有 <scope>test</scope>
,因此它仅在构建期间对 test/java
内的源可见。
我在构建环境中构建 Spring 引导应用程序时收到以下编译错误。但是,当 运行 Junit 在我的机器上本地测试或构建(打包)它时,我没有看到任何错误 -
src/main/java/com/abc/tests/AbcTest.java : package org.junit does not exist
这是我的 pom.xml -
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath />
</parent>
<dependencies>........
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
这是我尝试过但没有成功的步骤 -
1. 在依赖部分中显式依赖 junit 4.12 和 [4.12]。
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency>
- 使用和不使用插件版本 2.18.1 添加 maven-surefire-plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <junitArtifactName> junit:junit:4.12</junitArtifactName> </configuration> </plugin>
有没有其他方法可以强制构建过程在 pom.xml 中使用 4.12 junit 版本,而不是选择像 3.8 这样的旧版本?
谢谢
您已将测试放在 main/java
而不是 test/java
中:src/main/java/com/abc/tests/AbcTest.java
Junit 依赖项具有 <scope>test</scope>
,因此它仅在构建期间对 test/java
内的源可见。