import failed using gradle dependency on windows 10 using IntelliJ Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of import failed using gradle dependency on windows 10 using IntelliJ without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am following the spring boot documentation https://spring.io/guides/gs/spring-boot/ but after I did the same as in Add Unit Tests step, even though I have the same gradle file, the project will not build because the import failed.

gs-spring-bootcompletesrcmainjavacomexamplespringbootHelloControllerTest.java:3: error: package org.hamcrest does not exist
import static org.hamcrest.Matchers.equalTo;
                      ^
error: package org.assertj.core.api does not exist
import static org.assertj.core.api.Assertions.*;

My gradle file content

plugins {
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
}

test {
    useJUnitPlatform()
}

and entire project setup same is given in https://github.com/spring-guides/gs-spring-boot/archive/master.zip

folder

What went wrong here? I have the java SDK setup and I am able to run the http server right before this step. I am on windows 10 using IntelliJ and its built in gradle.

Answer

Not sure if this is still a useful answer, but I also ran into this issue.

The problem seems to be that your code is in the ‘main’ directory instead of the ‘test’ directory. Moving the test files into the test directory fixed this problem for me.

We are here to answer your question about import failed using gradle dependency on windows 10 using IntelliJ - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji