Skip to main content

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:
project/
├── src/
│   └── main/
│       └── java/
│           └── frc/
│               └── robot/
│                   ├── Robot.java
│                   └── Main.java
├── build.gradle
└── settings.gradle

Gradle Configuration

build.gradle Setup

WPILib projects use specific Gradle plugins and repositories. Here’s the essential configuration based on the WPILib source:
plugins {
    id 'java'
    id 'edu.wpi.first.GradleRIO' version '2024.3.2'
}

repositories {
    maven {
        url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
}

dependencies {
    implementation wpi.java.deps.wpilib()
    implementation wpi.java.vendor.java()

    nativeRelease wpi.java.deps.wpilibJni(wpi.platforms.roborio)
    nativeDebug wpi.java.deps.wpilibJni(wpi.platforms.roborio)

    testImplementation 'junit:junit:4.13.2'
}

Compiler Options

WPILib requires UTF-8 encoding for all source files:
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
    options.compilerArgs.add '-XDstringConcat=inline'
}

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

dependencies {
    // Core WPILib
    implementation 'edu.wpi.first.wpilibj:wpilibj-java:2024.+'
    implementation 'edu.wpi.first.wpimath:wpimath-java:2024.+'
    implementation 'edu.wpi.first.wpiutil:wpiutil-java:2024.+'
    implementation 'edu.wpi.first.ntcore:ntcore-java:2024.+'
    
    // Vision (optional)
    implementation 'edu.wpi.first.cscore:cscore-java:2024.+'
    implementation 'edu.wpi.first.cameraserver:cameraserver-java:2024.+'
}

Building and Deploying

1
Build the project
2
Compile your robot code:
3
./gradlew build
4
Deploy to robot
5
Deploy code to the roboRIO:
6
./gradlew deploy
7
Run tests
8
Execute unit tests:
9
./gradlew test

IDE Setup

WPILib provides a VS Code extension with integrated build and deploy tools.
  1. Install the WPILib VS Code extension
  2. Open your project folder
  3. Use Ctrl+Shift+P to access WPILib commands

IntelliJ IDEA

For IntelliJ users:
plugins {
    id 'idea'
}
Then import the project as a Gradle project.

Common Tasks

Clean Build

Remove all build artifacts:
./gradlew clean

Simulate Robot

Run robot code in simulation:
./gradlew simulateJava

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

Build docs developers (and LLMs) love