spring boot build package org.junit does not exist

13,364

You have put your test inside the main/java instead of test/java: src/main/java/com/abc/tests/AbcTest.java

The Junit dependency has the <scope>test</scope> so it is only visible to sources inside the test/java during the build time.

Share:
13,364
chappalprasad
Author by

chappalprasad

Updated on June 17, 2022

Comments

  • chappalprasad
    chappalprasad almost 2 years

    I am receiving below compilation error while building Spring Boot application in a build env. However I don't see any error while running Junit test or building(package) it locally on my machine -

    src/main/java/com/abc/tests/AbcTest.java : package org.junit does not exist

    Here is my 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>
    

    Here are the Steps i tried with no success -
    1. placing explicit dependency on junit 4.12 as well as [4.12] in dependency section.

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>  
    </dependency> 
    
    1. adding maven-surefire-plugin with and without version 2.18.1 of plugin
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
            <junitArtifactName> junit:junit:4.12</junitArtifactName>
        </configuration>
    </plugin>
    

    Is there any other way to force the build process to use 4.12 junit version within pom.xml instead of picking some old version like 3.8 ?

    Thanks