0

Below is my build.gradle file

plugins {
    id 'org.springframework.boot' version '2.3.4.RELEASE'

    id 'java'
}

group = 'jwt.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    flatDir {
        dirs 'C://Users//David//.gradle//caches//modules-2//files-2.1'
    }
}
dependencies {
    implementation 'org.springframework.boot:spring-boot-starter:2.3.4.RELEASE'
    implementation 'org.springframework.boot:spring-boot-starter-web:2.3.4.RELEASE'


}
test {
    useJUnitPlatform()
}

When i click on build and assemble icon of the Gradle panel on the intelliji, it shows "BUILD SUCCESFUL" But when i add spring boot annotation @SpringBoot, it shows error " cannot resolve symbol SpringbootApplication". It seems it was not compiled succesfully. Any ideas how to fix it ?

kungho
  • 371
  • 1
  • 4
  • 16
  • Does this answer your question? [Cannot Resolve Symbol @SpringBootApplication - IntelliJ DEA](https://stackoverflow.com/questions/52633342/cannot-resolve-symbol-springbootapplication-intellij-dea) – Dariusz Urbanek Oct 09 '20 at 12:54

1 Answers1

1

TL;DR use the Spring Initializr for a proper project setup. Here's why.

flatDir repositories and especially defining the Gradle cache directory as source are not suitable to develop a Spring Boot application for the following reasons:

  • The Gradle shared cache directory is an internal construct of Gradle where it stores resolved artifacts from remote repositories. It is initially empty by default. Resolved but unused artifacts get removed after a certain period of time. The structure of the cache makes is also not suitable for flatDir which expects jars rather than directory structures in the directory defined.
  • flatDir does not support any meta-data formats like Ivy XML or Maven POM files, hence dependency information is unavailable. spring-boot-starter and spring-boot-starter-web define lots of dependencies in their respective POMs. Standalone they're quite useless.

You're better off to use a proper (public) Maven repository. Gradle has built-ins for Maven Central (mavenCentral()), JCenter (jcenter()) and Google (google()). Gradle caches the resolved artifacts so that they're usually resolved only once. Read more about this in the official documentation: Declaring a publicly-available repository.

You may also want to use the Spring Initializr that will generate a working project and build file for you.

thokuest
  • 5,800
  • 24
  • 36