0

I am facing an error dowloading junit from mavenCentral.

The error:

> Could not find method testImplementation() for arguments [org.junit.jupiter:junit-jupiter-api:5.9.3] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Of course I have already checked and the dependency exists in maven central repository. The build gradle file is quite easy and I am using a gradle wrapper.

build.gradle

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
}

test {
    useJUnitPlatform()
}

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Any idea what to check?

  • Per the https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api/5.9.3 link it shows this as the proper syntax to list it as a dependency `testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")` – CAMD_3441 Jun 28 '23 at 11:44
  • @CAMD_3441 already tested this syntax too and I have the same error – Elena Guidi Jun 28 '23 at 11:46

1 Answers1

0

testImplementation is a configuration that is added by a plugin.
But you do not have any plugins applied.
If you for example apply the java plugin, or java-application plugin, or groovy plugin, or application plugin, ..., the configuration is added and can be used to define dependencies.

Vampire
  • 35,631
  • 4
  • 76
  • 102