Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 315
Ivan Aracki Avatar asked Oct 29 '15 14:10

Ivan Aracki


People also ask

What would be Springboot have security starter dependency?

Spring Boot provides a spring-boot-starter-security starter which aggregates Spring Security related dependencies together. The simplest and preferred method to leverage the starter is to use Spring Initializr using an IDE integration (Eclipse, IntelliJ, NetBeans) or through https://start.spring.io.

What is security starter in spring boot?

Spring Boot provides a spring-boot-starter-security starter that aggregates Spring Security related dependencies together. The simplest and preferred method to use the starter is to use Spring Initializr by using an IDE integration (Eclipse, IntelliJ, NetBeans) or through start.spring.io.


1 Answers

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
like image 85
Ivan Aracki Avatar answered Sep 17 '22 21:09

Ivan Aracki