How to make a dependsOn in build.gradle for deploy to robot

I am trying to implement the feature talked about by South Eugene Robotics in this thread: Smart Dashboard Version Display with one added feature, I want to print the host name of the computer used to deploy the jar file to the robot. Of course the deploy host can’t be in the jar file so I am creating a plain file to be deployed in the src/main/resources directory, which I believe should automatically get deployed to the roboRIO /home/lvuser/deploy directory. I did this by adding this task to the build.gradle file:

task deployHost() {
    doLast {
        String deploy_host = ""
        String deployDir = "$projectDir/src/main/deploy"
        try {
             deploy_host = java.net.InetAddress.getLocalHost().getHostName()
        } catch (all) {
             deploy_host = "unknown"
        }
        new File("$deployDir/deployhost.txt").text = deploy_host
        new File("$deployDir/deploytime.txt").text = 
            new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())
     }
 }

However, for the other things in the original thread I added a line like this:

build.dependsOn = versionTxt

to cause the version files to be written when the build is done. However, I want the task above to execute just before the deploy is done. I tried adding this line:

deploy.dependsOn = deployHost

but that throws an error

Could not find method dependsOn() for arguments [task ‘:deployHost’] on object of type jaci.gradle.deploy.DeployExtension.

So deploy apparently isn’t a pre-defined target. In fact, the build.gradle file itself already has a block labeled “deploy”. Does anyone have any idea how I can get my deployHost task to run just before deploying the files to the roboRIO?

I stumbled upon this looking for the same answer. I dunno how gradle allows deploy to be used for both a Task and DeployExtension, but to get the Task, I found this works.

// deploy.dependsOn = deployHost
tasks.getByName('deploy').dependsOn(deployHost)

That works great. I added one with “simulateExternalJava” to update the files when I run a desktop simulation as well.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.