Cannot add Spring dependencies with Gradle

Refresh

April 2019

Views

4.4k time

1

I am new to Spring, and I am trying to create a simple Spring Boot "hello world" application, so I created a build.gradle file to add Spring Boot dependency:

apply plugin: 'java'

repositories {
    jcenter()
}

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE")
}

The problem is that it does not add the required jar(s), so I cannot use Spring annotations, such as @Controller.

What am I missing to make it work?

I am using IntelliJ Idea 2016.1, if this can help.

2 answers

0
    buildscript {
        repositories {
             mavenLocal()
             jcenter()
        }
        dependencies {
            classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: '1.3.3.RELEASE'
        }
    }

    apply plugin: 'java'

    repositories {
        jcenter()
    }

    dependencies {
        compile("org.springframework.boot:spring-boot-starter-web")
    }
4

This would help you :

http://start.spring.io/

just setup your dep and this include them all as a starter kit :) Enjoy