Overview
WPILib uses Gradle as its build system for Java projects. This guide covers setting up a Java robot project from scratch.Prerequisites
- Java Development Kit (JDK) 17 or higher
- WPILib installation
- Gradle 8.14.3 or higher
Project Structure
A typical WPILib Java project has the following structure:Gradle Configuration
build.gradle Setup
WPILib projects use specific Gradle plugins and repositories. Here’s the essential configuration based on the WPILib source:Compiler Options
WPILib requires UTF-8 encoding for all source files:Dependencies
Core WPILib Components
Add these dependencies to use WPILib features:- wpilibj: Core robot framework
- wpimath: Math utilities and kinematics
- wpiutil: Utility classes
- ntcore: NetworkTables
- cscore: Camera server (optional)
- cameraserver: Camera streaming (optional)
Example Dependency Declaration
Building and Deploying
IDE Setup
VS Code (Recommended)
WPILib provides a VS Code extension with integrated build and deploy tools.- Install the WPILib VS Code extension
- Open your project folder
- Use
Ctrl+Shift+Pto access WPILib commands
IntelliJ IDEA
For IntelliJ users:Common Tasks
Clean Build
Remove all build artifacts:Simulate Robot
Run robot code in simulation:Troubleshooting
Build Errors
- Ensure Java 17+ is installed and set as JAVA_HOME
- Clear Gradle cache:
./gradlew clean --refresh-dependencies - Check network connection for dependency downloads
Deployment Issues
- Verify roboRIO is connected and powered
- Check team number in build.gradle
- Ensure roboRIO has the correct image
Next Steps
- Basic Robot Program - Create your first robot program
- Motor Control - Control motors
- Sensors - Read sensor data