Most likely this is my inexperience building Java projects, so I would appreciate even the obvious answer here as I am stuck.
I pulled down the latest master version of the Java JWT library from Git. When running the "gradle compile ‘com.auth0:java-jwt:3.4.0’ command referenced in the ReadMe (I did read it several times), I am getting a build error stating …
Build file ‘build.gradle’ line: 60
A problem occurred evaluating project ‘:java-jwt’.
Cannot add task ‘clean’ as a task with that name already exists.
Any ideas what I might be missing here or is there other relevant debug information I can provide?
TIA!
I had this exact same problem (unfamiliar with Java build tools, same error). A Google search led me here, where I saw no answer. I looked through the source a little and noticed a reference to an older version of Gradle (2.14). I tried to use that instead, but the build failed for a new reason.
Task ‘compile’ is ambiguous in root project ‘java-jwt’. Candidates are: ‘compileJava’, ‘compileTestJava’.
What I really needed was a JAR file. I tried gradle jar
instead of gradle compile
. It worked, but I saw this warning in the build output:
Defining custom ‘clean’ task when using the standard Gradle lifecycle plugins has been deprecated and is scheduled to be removed in Gradle 3.0
So I think the clean error is related to the Gradle version.
I later figured out that I did not need to manually download and install the older version of Gradle . I could have used the Gradle wrapper included in the project instead. You invoke it via gradlew
or gradlew.bat
in the root. I’ll include instructions in case someone else discovers this and is similarly unfamiliar with these tools.
-
Download/clone the java-jwt project from Github
-
Open your favorite CL tool and navigate to the project root
-
Run gradlew setupDecompWorkspace
(seemed to download a “wrapped” local version to my user profile – I could not find much documentation about this, but I didn’t look very hard)
-
To create a JAR file without dependencies: Run gradlew jar
-
To create a JAR file with dependencies (Gradle does not do this for you, I discovered painfully, though I did get the impression there are good reasons for this – I am doing proof-of-concept so this was desirable in my case): You can use the Shadow plugin. You do not need to install it. Open lib\build.gradle
and add the following. I don’t know if there’s a better or more correct way, I just know that this worked for me (see // <--
for added parts):
apply plugin: 'jacoco'
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow' // <--
apply from: '../scripts/release.gradle'
apply from: '../scripts/maven.gradle'
apply from: '../scripts/bintray.gradle'
logger.lifecycle("Using version ${version} for ${group}.${name}")
jar.enabled = false // <--
build.dependsOn(shadowJar) // <--
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1'
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
}
} // <--
Now run gradle shadowJar
. The file should be much larger than the one that gets generated without the dependencies.
Hopefully this helps someone. Edits/corrections welcome.
2 Likes