Gradle failing to build

Programming mentor from Team 3157 here. We have been getting Gradle issues today on all of our laptops. Today I completely uninstalled the wpilib (followed the removal instructions located at the bottom of https://docs.wpilib.org/en/latest/docs/getting-started/getting-started-frc-control-system/wpilib-setup.html) and reinstalled it, yet we are still receiving this issue.

We are lost at solving this. Whenever I try to build the code, offline or online, I get the following output in the terminal:

Executing task: gradlew build -Dorg.gradle.java.home=“C:\Users\Public\wpilib\2020\jdk” <

The terminal process command ‘cmd.exe /d /c gradlew build -Dorg.gradle.java.home=“C:\Users\Public\wpilib\2020\jdk”’ failed to launch (exit code: {2})

Terminal will be reused by tasks, press any key to close it.

We are using VS Code on Windows. A lot of our progress is being hindered because of this error.

Has anyone received this issue before? Does anyone know what is causing this issue? How to solve it? Thank you.

Are you using the most up to date gradle version?

Make sure that the folder you have open in VSCode is the project folder, the one that contains the src directory. Sometimes if you have open a folder that contains your project folder instead of the project folder itself, gradle won’t build.

In the past this has helped me as well so try that first.

Yep, I am using 2.2.

That is not the issue for us, but thank you. We are not able to build or deploy our code in VS Code because Gradle commands are failing to execute, e.g. gradlew build.

Could you please post the contents of your gradlew.bat file.

@rem

@rem Copyright 2015 the original author or authors.

@rem

@rem Licensed under the Apache License, Version 2.0 (the "License");

@rem you may not use this file except in compliance with the License.

@rem You may obtain a copy of the License at

@rem

@rem      https://www.apache.org/licenses/LICENSE-2.0

@rem

@rem Unless required by applicable law or agreed to in writing, software

@rem distributed under the License is distributed on an "AS IS" BASIS,

@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

@rem See the License for the specific language governing permissions and

@rem limitations under the License.

@rem

@if "%DEBUG%" == "" @echo off

@rem ##########################################################################

@rem

@rem  Gradle startup script for Windows

@rem

@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell

if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0

if "%DIRNAME%" == "" set DIRNAME=.

set APP_BASE_NAME=%~n0

set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.

set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe

if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe

%JAVA_EXE% -version >NUL 2>&1

if "%ERRORLEVEL%" == "0" goto init

echo.

echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

echo.

echo Please set the JAVA_HOME variable in your environment to match the

echo location of your Java installation.

goto fail

:findJavaFromJavaHome

set JAVA_HOME=%JAVA_HOME:"=%

set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.

echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%

echo.

echo Please set the JAVA_HOME variable in your environment to match the

echo location of your Java installation.

goto fail

:init

@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args

@rem Slurp the command line arguments.

set CMD_LINE_ARGS=

set _SKIP=2

:win9xME_args_slurp

if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute

@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

@rem Execute Gradle

"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

:end

@rem End local scope for the variables with windows NT shell

if "%ERRORLEVEL%"=="0" goto mainEnd

:fail

rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of

rem the _cmd.exe /c_ return code!

if  not "" == "%GRADLE_EXIT_CONSOLE%" exit 1

exit /b 1

:mainEnd

if "%OS%"=="Windows_NT" endlocal

:omega

This is still one of the reasons that it might not execute. I encourage you to check.

Your gradlew.bat file looks correct, so that is probably not the problem.

Thanks for checking. Are there other files you recommend I look at which are related to building Gradle? I spent time trying to find other ones but I am out of luck.

One thing that would be worth a try is launching it directly from Command Prompt or PowerShell. This can make sure it is launching from the correct directory. I would also check to see if Java is available and in the path. I know this seems obvious, but restarting your computer might be helpful. I don’t know how Java installs on Windows handles it, but it might need a restart

I can take a look at your build.gradle file.

plugins {

    id "java"

    id "edu.wpi.first.GradleRIO" version "2020.2.2"

}

sourceCompatibility = JavaVersion.VERSION_11

targetCompatibility = JavaVersion.VERSION_11

def ROBOT_MAIN_CLASS = "frc.robot.Main"

// Define my targets (RoboRIO) and artifacts (deployable files)

// This is added by GradleRIO's backing project EmbeddedTools.

deploy {

    targets {

        roboRIO("roborio") {

            // Team number is loaded either from the .wpilib/wpilib_preferences.json

            // or from command line. If not found an exception will be thrown.

            // You can use getTeamOrDefault(team) instead of getTeamNumber if you

            // want to store a team number in this file.

            team = frc.getTeamNumber()

        }

    }

    artifacts {

        frcJavaArtifact('frcJava') {

            targets << "roborio"

            // Debug can be overridden by command line, for use with VSCode

            debug = frc.getDebugOrDefault(false)

        }

        // Built in artifact to deploy arbitrary files to the roboRIO.

        fileTreeArtifact('frcStaticFileDeploy') {

            // The directory below is the local directory to deploy

            files = fileTree(dir: 'src/main/deploy')

            // Deploy to RoboRIO target, into /home/lvuser/deploy

            targets << "roborio"

            directory = '/home/lvuser/deploy'

        }

    }

}

// Set this to true to enable desktop support.

def includeDesktopSupport = false

// Defining my dependencies. In this case, WPILib (+ friends), and vendor libraries.

// Also defines JUnit 4.

dependencies {

    implementation wpi.deps.wpilib()

    nativeZip wpi.deps.wpilibJni(wpi.platforms.roborio)

    nativeDesktopZip wpi.deps.wpilibJni(wpi.platforms.desktop)

    implementation wpi.deps.vendor.java()

    nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)

    nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)

    testImplementation 'junit:junit:4.12'

    // Enable simulation gui support. Must check the box in vscode to enable support

    // upon debugging

    simulation wpi.deps.sim.gui(wpi.platforms.desktop, false)

}

// Setting up my Jar File. In this case, adding all libraries into the main jar ('fat jar')

// in order to make them all available at runtime. Also adding the manifest so WPILib

// knows where to look for our Robot Class.

jar {

    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }

    manifest edu.wpi.first.gradlerio.GradleRIOPlugin.javaManifest(ROBOT_MAIN_CLASS)

}

I agree. You can also post a screenshot of your file tree and I can look at that.

Thank you. What specifically do you want me to execute? gradlew build?

Yes. In Powershell (which is what I use for most things), I have to run ./gradlew build in the root of the project. I think in Command Prompt you run without the ./

1 Like

Here is the output:

I believe the issue is with the JDK. Any tips on how to fix this?

You can change your java version to match in your build.gradle file. You are trying to run 11, even though you have 1.8.

1 Like

Gradle will deploy Java 11 to the roborio, you will need to install Java 11 or later. I would install Java 13, such as from https://jdk.java.net/13/

1 Like