Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Spring Basics Spring Components and Configuring Our App Configuring Gradle for Spring Development

Gradle build not working

THis is what I have group 'com.teamtreehouse' version '1.0-SNAPSHOT'

buildscript{ repositories{ mavenCentral() } dependencies{ classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE' } }

apply plugin: 'java' apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.M7'

}

IT isn't working. The console says 'the supplied build action failed with an exception' but nothing else. Any ideas?

10 Answers

Michael Switzer
Michael Switzer
7,489 Points

It seems Gradle doesn't use "buildscript" anymore. As of March 20, 2019, this gradle build file worked for me:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.1.3.RELEASE'
}

group 'giflib'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework.boot:spring-boot-starter-web:2.1.3.RELEASE'
}

Yes, and the current version of spring-boot is 2.2.6 now

Jose Luis Jiménez Sastre
Jose Luis Jiménez Sastre
12,314 Points

This work for me:

buildscript{
    repositories{
        mavenCentral()
    }
    dependencies{
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.12.RELEASE'
    }
}

plugins {
    id 'java'
    id "org.springframework.boot" version "1.5.12.RELEASE"
}

group 'com.teamtreehouse'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.5.12.RELEASE'
}

It depend of Gradle's version you have.

Jeroen Oosterwijk
Jeroen Oosterwijk
5,456 Points

Had the same problem, after playing around with the version, this is what worked for me:

group 'com.teamtreehouse' version '1.0-SNAPSHOT'

buildscript { repositories{ mavenCentral() } dependencies{ classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.10.RELEASE' } }

apply plugin: 'java' apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories { mavenCentral() }

dependencies { compile "org.springframework.boot:spring-boot-starter-web:1.5.10.RELEASE"

}

As of today, this is the preferred syntax for the Gradle file:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.3.4.RELEASE'
}
group 'com.treehouse'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web:2.3.4.RELEASE'
}

Notice the word 'implementation' instead of 'compile.' Since Gradle 3.4, 'compile' has been deprecated. See the documentation here and here for reference.

Gene Higgins
Gene Higgins
16,580 Points

You will have to go to the Gradle page to see what the buildscript should look like for your springframework.boot version. E.g., for version 1.5.10

Also you guys should be putting your code into code tags to make it more readable. Reference the Markdown Cheatsheet below.

Money Maker
Money Maker
1,196 Points

try this..

buildscript{ repositories { mavenCentral() } dependencies { classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.5.9.RELEASE' } }

apply plugin: 'java' apply plugin: 'spring-boot'

sourceCompatibility = 1.5

repositories { mavenCentral() }

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

Try using: apply plugin: 'org.springframework.boot'

alastair cooper
alastair cooper
28,201 Points

use the answer from Michael Switzer above and then change your version of gradle by editing the gradle-wrapper.properties file. Sounds complicated but It is very easy and worked great for me

instructions at link below (find the file by right clicking the gradle directory and selecting show in explorer)

https://better-coding.com/solved-spring-boot-plugin-requires-gradle-4-0-or-later-the-current-version-is-gradle-x-x/

Ronald Williams
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Ronald Williams
Java Web Development Techdegree Graduate 25,021 Points

I suggest trying a different version of your dependencies. A lot of times when I get errors with gradle builds, changing the versions to newer ones helps. For example google "org.springframework.boot dependency" to find the other version of that one. Also in the video his source compatibility is 1.5

Jose Mejia
Jose Mejia
16,750 Points

same here it gave an error!!