springframework.security package not found with starter-security dependency?

I’m using spring boot and spring starter dependencies for my project. I tried with spring starter security dependency in Gradle, but only security packages are not found in project. IDE is IntelliJ IDEA‎.

My build.gradle file :

buildscript {
    ext {
        springBootVersion = '1.2.7.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
        classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
        classpath("org.springframework:springloaded:1.2.4.RELEASE")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot' 
apply plugin: 'io.spring.dependency-management' 

jar {
    baseName = 'hashfon-spring'
    version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-hateoas')
    compile('org.springframework.boot:spring-boot-starter-jersey')
    compile('org.springframework.boot:spring-boot-starter-mustache')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('org.springframework.boot:spring-boot-starter-security')

    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test') 
}

All libraries except security can be found in External Libraries

One example of class in project:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.*;
import org.springframework.hateoas.*;
import org.springframework.mock.*;
import org.springframework.data.*;
import org.springframework.security.*;  //cannot resolve symbol!
/**
 * I can import all packages from external libraries except security
 */

PS. I tried with a lot of different release versions of spring-security-core and nothing happens.

Answer

After dealing with this issue multiple times I came across following solution which works for me 100%:

  1. Go to File | Invalidate Caches
  2. Delete folder where all dependencies are stored (~/.gradle/ for UNIX systems) – if it exists after invalidation
  3. Restart Intellij IDEA
  4. Reimport gradle dependencies by refreshing gradle: enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *