簡體   English   中英

spring boot build package org.junit不存在

[英]spring boot build package org.junit does not exist

我在構建環境中構建Spring Boot應用程序時收到以下編譯錯誤。 但是,在我的機器上運行Junit測試或構建(打包)它時,我沒有看到任何錯誤 -

src / main / java / com / abc / tests / AbcTest.java:包org.junit不存在

這是我的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> 
  1. 添加帶有和不帶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/javasrc/main/java/com/abc/tests/AbcTest.java

Junit依賴項具有<scope>test</scope>因此只有在構建期間test/java內的源可見。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM