Skip to content

Commit

Permalink
Add kotlin docs for GVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
falOn-Dev committed Sep 7, 2024
1 parent c627b7f commit 02664df
Showing 1 changed file with 76 additions and 33 deletions.
109 changes: 76 additions & 33 deletions source/docs/software/advanced-gradlerio/deploy-git-data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,49 +17,92 @@ plugins {

In order to generate the file when building the project, add the following block to the bottom of ``build.gradle``.

```groovy
project.compileJava.dependsOn(createVersionFile)
gversion {
srcDir = "src/main/java/"
classPackage = "frc.robot"
className = "BuildConstants"
dateFormat = "yyyy-MM-dd HH:mm:ss z"
timeZone = "America/New_York" // Use preferred time zone
indent = " "
}
```
.. tab-set::
.. tab-item:: Java
```groovy
project.compileJava.dependsOn(createVersionFile)
gversion {
srcDir = "src/main/java/"
classPackage = "frc.robot"
className = "BuildConstants"
dateFormat = "yyyy-MM-dd HH:mm:ss z"
timeZone = "America/New_York" // Use preferred time zone
indent = " "
language = "java"
}
```

.. tab-item:: Kotlin
```groovy
project.compileJava.dependsOn(createVersionFile)
gversion {
srcDir = "src/main/java/"
classPackage = "frc.robot"
className = "BuildConstants"
dateFormat = "yyyy-MM-dd HH:mm:ss z"
timeZone = "America/New_York" // Use preferred time zone
indent = " "
language = "kotlin"
}
```

The ``srcDir``, ``classPackage``, and ``className`` parameters tell the plugin where to put the manifest file, and what to name it. The ``timeZone`` field can be set to your team's time zone based on [this list of timezone IDs](https://docs.oracle.com/middleware/12211/wcs/tag-ref/MISC/TimeZones.html). The ``dateFormat`` parameter is based on [this Java class](https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html).

To test this, run a build of your project through the WPILib menu in the top right. Once the code has finished building, there should be a file called ``BuildConstants.java`` in your ``src/main/java`` folder. The following is an example of what this file should look like:

```Java
package frc.robot;
/**
* Automatically generated file containing build version information.
*/
public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "GitVersionTest";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 1;
public static final String GIT_SHA = "fad108a4b1c1dcdfc8859c6295ea64e06d43f557";
public static final String GIT_DATE = "2023-10-26 17:38:59 EDT";
public static final String GIT_BRANCH = "main";
public static final String BUILD_DATE = "2023-10-27 12:29:57 EDT";
public static final long BUILD_UNIX_TIME = 1698424197122L;
public static final int DIRTY = 0;
private BuildConstants(){}
}
```
.. tab-set::
.. tab-item:: Java
```Java
package frc.robot;
/**
* Automatically generated file containing build version information.
*/
public final class BuildConstants {
public static final String MAVEN_GROUP = "";
public static final String MAVEN_NAME = "GitVersionTest";
public static final String VERSION = "unspecified";
public static final int GIT_REVISION = 1;
public static final String GIT_SHA = "fad108a4b1c1dcdfc8859c6295ea64e06d43f557";
public static final String GIT_DATE = "2023-10-26 17:38:59 EDT";
public static final String GIT_BRANCH = "main";
public static final String BUILD_DATE = "2023-10-27 12:29:57 EDT";
public static final long BUILD_UNIX_TIME = 1698424197122L;
public static final int DIRTY = 0;
private BuildConstants(){}
}
```
.. tab-item:: Kotlin
```kotlin
package frc.robot
/**
* Automatically generated file containing build version information.
*/
const val MAVEN_GROUP = ""
const val MAVEN_NAME = "GitVersionTest"
const val VERSION = "unspecified"
const val GIT_REVISION = 1
const val GIT_SHA = "fad108a4b1c1dcdfc8859c6295ea64e06d43f557
const val GIT_DATE = "2023-10-26 17:38:59 EDT"
const val GIT_BRANCH = "main"
const val BUILD_DATE = "2023-10-27 12:29:57 EDT"
const val BUILD_UNIX_TIME = 1698424197122
const val DIRTY = 0
```

``DIRTY`` indicates whether there are uncommitted changes in the project. A value of 0 indicates a clean repository, a value of 1 indicates that there are uncommitted changes, and a value -1 indicates an error.

### Ignoring Generated Files with Git

These files are regenerated every time code is built or deployed, so it isn't necessary to track them with Git. The aptly named [.gitignore](https://git-scm.com/docs/gitignore) file tells Git not to track any listed files and should exist by default in any project generated by the WPILib VS Code extension. Below is the line you should add to ``.gitignore`` to ignore the generated file:

```
src/main/java/frc/robot/BuildConstants.java
```
.. tab-set::
.. tab-item:: Java
```text
src/main/java/frc/robot/BuildConstants.java
```
.. tab-item:: Kotlin
```text
src/main/java/frc/robot/BuildConstants.kt
```

0 comments on commit 02664df

Please sign in to comment.