I’m new to coding and I got WpILIb and got this error.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
The terminal process "cmd.exe /d /c gradlew build " terminated with exit code: 1.
I searched on the web and I found out that this error had something to do with gradle-wrapper.jar missing. But I have it under gradle/wrapper. So what should I do so that I am able to build robot code?
I’m assuming that you’re using VS Code. Are you sure that you’re opening the right project folder? There should be a build.gradle
file in the most outer folder in VS Code. If you want to make sure, write dir
in the VS Code terminal and check that build.grade
is in the output.
Does a fresh project work correctly?
Thank you for the response. I checked and I’m pretty sure that build.gradle is not under any folder.
And build.gradle came up after writing dir in the terminal. Do you have any other suggestions?
When do you get that error? Can you go to the command palette (under view) and choose WPILib: Build Robot Code?
Do you have the code posted on Github or online somewhere?
The error appears when I try to do WPILIB: Build Robot Code on VS code’s command palette.
Also, I do not have the code online since it’s just the WPILIB create a new project with nothing edited.
Is it a specific example or a template? Do other things build or does everything have this issue?
What version of WPILib is installed?
So, I have WPILib 2021.2.2 and the template I used is the one you get from typing WPILib: build robot code in the VS Code command palette.
So by template/example I was referring to you do “WPILib: Create a new robot project” then from there you can choose Example/Template, Java/C++, and ProjectBase. I am assuming you did Template, then Java, then what did you select for project base? I just created a new project like this choosing TimedRobot and it built fine.
For the project base, I chose TimedRobot. And when I went to do WPILib: Build Robot Code it gave me the error I put on the original post. So, I am clueless about what is causing the problem and what I need to do to fix it.
Do you have the latest version of wpilib installed correctly? The wpilib extension in vscode should not be installed manually, instead, use this method from the wpilib docs to install it. The installer will install a separate copy of vscode for wpilib 2021 (with the correct extensions), gradle, a java jdk, etc. It should then work if you use the “wpilib vscode 2021” shortcut on the desktop.
I followed the steps on WPILib Installation Guide, but I got an error that was slightly different.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
The terminal process “cmd.exe /d /c gradlew build -Dorg.gradle.java.home=“C:\Users\Public\wpilib\2021\jdk”” terminated with exit code: 1.
So fresh install of WPILib seemed to have not helped. Any other suggestions?
Can you try to delete the C:\Users\Public\wpilib directory and try to run the installer again?
I deleted the files in the WPILib directory and run the installer again, but the same error popped up. So seems like the install of WPILib was not the problem.
Does it only happen on this one project, or any new project you create?
The same error appears on any new project I make.
@Deltapla Can you try to delete the Gradle cache directory ($USER_HOME/. gradle
) and try to rebuild?
@Daltz3 Didn’t you see something happen once with a corrupt Gradle cache?
Ummm, I’m a n00b so how do you exactly delete the Gradle cache directory?
Navigate to C:/Users/USER/.gradle
using Windows file explorer and delete the entire folder.
i deleted the .gradle cache directory but the same error appeared.