Could not find withJavadocJar() and withSourcesJar()

When trying to use

java {
    withJavadocJar()
    withSourcesJar()
}

to generate sources and javadoc, I get the following error:

A problem occurred evaluating root project 'simple-cli'.
> Could not find method withJavadocJar() for arguments [] on object of type org.gradle.api.plugins.internal.DefaultJavaPluginExtension.

I’ve got my build.gradle set up like shown in the examples of the Maven Publish plugin.
I am using IntelliJ IDEA 2019.3.1, Java 8.0.232, Gradle 6.0.1, and Maven 3.6.3.

Do you have any idea what might be going wrong here?

1 Like

I too had that issue. I’ll mention a couple of things for you / others to check.

I checked my gradle wrapper version with:

➜  kafka-binary git:(master) ✗ ./gradlew --version

------------------------------------------------------------
Gradle 5.5.1
------------------------------------------------------------

Build time:   2019-07-10 20:38:12 UTC
Revision:     3245f748c7061472da4dc184991919810f7935a5

Kotlin:       1.3.31
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          9.0.4 (Oracle Corporation 9.0.4+11)
OS:           Mac OS X 10.14.6 x86_64

I then upgraded to 6.0.1 with:

➜  kafka-binary git:(master) ✗ ./gradlew wrapper --gradle-version=6.0.1

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed
➜  kafka-binary git:(master) ✗ ./gradlew --version                     

------------------------------------------------------------
Gradle 6.0.1
------------------------------------------------------------

Build time:   2019-11-18 20:25:01 UTC
Revision:     fad121066a68c4701acd362daf4287a7c309a0f5

Kotlin:       1.3.50
Groovy:       2.5.8
Ant:          Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM:          9.0.4 (Oracle Corporation 9.0.4+11)
OS:           Mac OS X 10.14.6 x86_64

My java block with withJavadocJar / withSourcesJar worked fine afterwards,

1 Like

Worked like a charm. Even though I created the project while only having Gradle 6.0.1 installed, IntelliJ IDEA made it a Gradle 5.x project.