Could not find method implementation()

Viewed 316

I know this was asked several times over but it looks like everything I try doesn't work.

Also I'm new to this and I am sorry if I make any mistakes.

And I try to build a java jar using Gradle and eclipse.

The Gradle build looks like this:

plugins {
    id 'org.springframework.boot' version '2.6.2'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}


repositories {
    mavenCentral()
    maven { url 'https://repo.spring.io/milestone' }
    maven { url 'https://repo.spring.io/snapshot' }
}

defaultTasks 'clean', 'bootJar'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-actuator'
    runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

test {
    useJUnitPlatform()
}

group = 'com.ericsson.opt'
//version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

But I always end up with :

Could not find method implementation() for arguments [org.springframework.boot:spring-boot-starter-data-jpa] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Now if I use compile instead of implement it is the same problem but with compile instead of implement. The Gradle I am using is :

Gradle --version

Gradle 7.4.2

Build time: 2022-03-31 15:25:29 UTC Revision: 540473b8118064efcc264694cbcaa4b677f61041

Kotlin:1.5.31 Groovy:3.0.9 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM:11.0.15 (Oracle Corporation 11.0.15+8-LTS-149) OS: Windows 10 10.0 amd64

And the eclipse plug-in for Gradle is Buildship Gradle Integration 3.0

What can cause this because I understand from previous searches it should be Gradle version related, but I think I'm on my last version.

Thank you,

1 Answers

You need to apply the java plugin first:

plugins {
  id 'java'
}

Spring Boot's plugins only react on the presence of the Java plugin, they don't apply the plugin on their own.

Related