Could not find method ... for arguments... on object of type org.gradle...DefaultDependencyHandler

Hello there,

mkdir my-test
cd my-test
gradle init
# I chose 2=application, 3=Java, 1=no, 1=Groovy, 4=Jupiter

Now I edit app/build.gradle ans insert this into the dependencies block, because I would like to use the javax.mail package (and as I understand it, it should be contained in one of these two).

dependencies {
   // [...]
    /*implementation 'javax:javaee-api:7.0' {
        because 'we parse emails using the javax.mail package'
    }*/
	implementation 'jakarta.platform:jakarta.jakartaee-api:9.1.0' {
        because 'we parse emails using the javax.mail package'
    }
}

However, a call of gradle build then results in

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\path\to\.eclipse\instancearea\my-test\app\build.gradle' line: 28

* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method jakarta.platform:jakarta.jakartaee-api:9.1.0() for arguments [build_5kis28hwmrz4c3vnhppz4xbks$_run_closure2$_closure5@1ec00a67] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

What am I doing wrong here?
I thought this is the way to add new dependecies. Unfortunately I cannot find anything helpful on the inet this time.

gradle --version

------------------------------------------------------------
Gradle 7.1.1
------------------------------------------------------------

Build time:   2021-07-02 12:16:43 UTC
Revision:     774525a055494e0ece39f522ac7ad17498ce032c

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          16.0.1 (Oracle Corporation 16.0.1+9-24)
OS:           Windows Server 2019 10.0 amd64

I appreciate any advice, thank you so much!

cheers

implementation 'jakarta.platform:jakarta.jakartaee-api:9.1.0'

is Groovy syntactic sugar for

implementation('jakarta.platform:jakarta.jakartaee-api:9.1.0')

What you actually want to call without sugar is (parentheses and comma)

implementation('jakarta.platform:jakarta.jakartaee-api:9.1.0', {
    because 'we parse emails using the javax.mail package'
})

for which there is for example this ugly sugared version

implementation 'jakarta.platform:jakarta.jakartaee-api:9.1.0', {
    because 'we parse emails using the javax.mail package'
}

or the nicer

implementation('jakarta.platform:jakarta.jakartaee-api:9.1.0') {
    because 'we parse emails using the javax.mail package'
}
1 Like