Skip to main content

Version Control

warning

When implementing this, keep in mind that:

  • Your robot code should be checked out from a Git repository.
  • The device that you build your robot code on must have git installed.

For logging Git version control information at runtime, we recommend the gradle plugin GVersion. This allows your code to be aware of its Git versions.

Installation

To install GVersion, add the following plugin to your gradle configuration:

TeamCode/build.gradle
plugins {
id "com.peterabeles.gversion" version "1.10.3"
}

Then, configure GVersion with your own timezone, date formats, language, etc.:

TeamCode/build.gradle
gversion {
srcDir = "src/main/java/"
classPackage = "org.firstinspires.ftc.teamcode"
dateFormat = "MMM d yyyy HH:mm:ss z"
timeZone = "PST" // Enter your timezone here
debug = false
language = "kotlin"
indent = " "
}

Finally, run GVersion every build by adding:

TeamCode/build.gradle
project(":TeamCode").preBuild.dependsOn(createVersionFile)

Run a gradle sync and a build, and then a file named GVersion will become available.

warning

This file updates with the latest information every time you build your robot code, and should not be checked into git. Add it to your .gitignore:

.gitignore
# GVersion
GVersion.kt

Metadata Logging

Now that you can access version control constants at runtime, use it however you would like. Here's an example for logging that information as metadata:

Logger.metadata += "Project" to MAVEN_GROUP
Logger.metadata += "BuildDate" to BUILD_DATE
Logger.metadata += "GitHash" to GIT_SHA
Logger.metadata += "GitBranch" to GIT_BRANCH
Logger.metadata += "GitDate" to GIT_DATE
Logger.metadata += "GitStatus" to when(DIRTY) {
0 -> "All Changes Commited"
1 -> "Uncommited Changes"
else -> "Unknown"
}