From 7b6023db185b9bbe0b2ec71e6e15149e5fe98505 Mon Sep 17 00:00:00 2001 From: Isaac Turner Date: Wed, 20 Mar 2024 12:14:05 +0800 Subject: [PATCH] get kotlin working --- .github/workflows/ci.yml | 2 +- testing/kotlin/build.gradle | 89 ++++++++++++------- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92d178d8..88887f4b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-22.04 strategy: matrix: - language: [cpp, java, asm] #, jni, kotlin] + language: [cpp, java, asm, kotlin] #, jni] steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 diff --git a/testing/kotlin/build.gradle b/testing/kotlin/build.gradle index 3fcd380e..77aea00e 100644 --- a/testing/kotlin/build.gradle +++ b/testing/kotlin/build.gradle @@ -1,73 +1,100 @@ plugins { - id "org.jetbrains.kotlin.jvm" version "1.3.50" + id "org.jetbrains.kotlin.jvm" version "1.9.20" id "edu.wpi.first.GradleRIO" version "2024.3.2" } +def projectFolder = project.buildFile.parentFile +def testingFolder = projectFolder.parentFile + +if (testingFolder.name != 'testing' || projectFolder.name != 'kotlin') { + throw new GradleException("These projects are not to be used for robot projects. See README.md in the GradleRIO testing folder for the correct templates to use.") +} + def ROBOT_MAIN_CLASS = "frc.team0000.robot.MainKt" // Define my targets (RoboRIO) and artifacts (deployable files) // This is added by GradleRIO's backing project DeployUtils. deploy { targets { - roboRIO("roborio") { + roborio(getTargetTypeClass('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' + team = project.frc.getTeamNumber() + debug = project.frc.getDebugOrDefault(false) + + artifacts { + // First part is artifact name, 2nd is artifact type + // getTargetTypeClass is a shortcut to get the class type using a string + + frcJava(getArtifactTypeClass('FRCJavaArtifact')) { + } + + // Static files artifact + frcStaticFileDeploy(getArtifactTypeClass('FileTreeArtifact')) { + files = project.fileTree('src/main/deploy') + directory = '/home/lvuser/deploy' + } + } } } } +def deployArtifact = deploy.targets.roborio.artifacts.frcJava + repositories { mavenCentral() } // Defining my dependencies. In this case, WPILib (+ friends) dependencies { - implementation wpi.deps.wpilib() - nativeZip wpi.deps.wpilibJni(wpi.platforms.roborio) - nativeDesktopZip wpi.deps.wpilibJni(wpi.platforms.desktop) + implementation wpi.java.deps.wpilib() + implementation wpi.java.vendor.java() + roborioDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.roborio) + roborioDebug wpi.java.vendor.jniDebug(wpi.platforms.roborio) - compile wpi.deps.vendor.java() - nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio) - nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop) + roborioRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.roborio) + roborioRelease wpi.java.vendor.jniRelease(wpi.platforms.roborio) + + nativeDebug wpi.java.deps.wpilibJniDebug(wpi.platforms.desktop) + nativeDebug wpi.java.vendor.jniDebug(wpi.platforms.desktop) + simulationDebug wpi.sim.enableDebug() + + nativeRelease wpi.java.deps.wpilibJniRelease(wpi.platforms.desktop) + nativeRelease wpi.java.vendor.jniRelease(wpi.platforms.desktop) + simulationRelease wpi.sim.enableRelease() - // We need to add the Kotlin stdlib in order to use most Kotlin language features. implementation "org.jetbrains.kotlin:kotlin-stdlib" } - // Simulation configuration (e.g. environment variables). -sim { - // Sets the websocket client remote host. - // envVar "HALSIMWS_HOST", "10.0.0.2" -} + +wpi.sim.addGui().defaultEnabled = true +wpi.sim.addDriverstation() + +//Sets the websocket client remote host. +wpi.sim.envVar("HALSIMWS_HOST", "10.0.0.2") +wpi.sim.addWebsocketsServer().defaultEnabled = true +wpi.sim.addWebsocketsClient().defaultEnabled = true // 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) + + duplicatesStrategy = DuplicatesStrategy.INCLUDE } +deployArtifact.jarTask = jar +wpi.java.configureExecutableTasks(jar) +wpi.java.configureTestTasks(test) + + wrapper { - gradleVersion = '6.8.1' + gradleVersion = '8.5' distributionType = Wrapper.DistributionType.BIN } diff --git a/testing/kotlin/gradle/wrapper/gradle-wrapper.properties b/testing/kotlin/gradle/wrapper/gradle-wrapper.properties index d050f177..ba66005b 100644 --- a/testing/kotlin/gradle/wrapper/gradle-wrapper.properties +++ b/testing/kotlin/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=permwrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=permwrapper/dists