From 17d6980e6f4fc97e6e068d7110d63b46159c12de Mon Sep 17 00:00:00 2001 From: Zachary Robinson Date: Tue, 9 Oct 2018 10:29:11 -0700 Subject: [PATCH] Make robot class property work nicely Now the jar task checks if the deploy task will run; if so, it does the checking if the robot class is set. This is a good deal better than the earlier band-aid solution which was to set it to a default. Now the build will succeed if robotClass is not set but we aren't deploying, but will fail if it is not set and we are deploying. --- test/build.gradle | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/build.gradle b/test/build.gradle index 4c886a9a..61f302b5 100644 --- a/test/build.gradle +++ b/test/build.gradle @@ -16,13 +16,6 @@ dependencies { def TEAM = 1540 -if (!project.hasProperty("robotClass")) { - println "Robot class not set! Pass a value in on the command line by adding -ProbotClass=. Using a default" -} - -def ROBOT_CLASS = project.hasProperty("robotClass") ? project.robotClass : "org.team1540.base.testing.HelloWorldTestRobot" -println "Will deploy robot $ROBOT_CLASS" - deploy { targets { target("roborio", RoboRIO) { @@ -44,6 +37,24 @@ deploy { } jar { + // declare the robot class property as an input, as normally since we + // set it at runtime this wouldn't run if the class changed due to up-to-date checking + inputs.property("robotClass", project.hasProperty("robotClass") ? project.robotClass : "") + gradle.taskGraph.whenReady { + /* + check if we are deploying to the robot. If we're building in CI, for example, the + robot class doesn't need to be set. + this is inside the gradle.taskGraph.whenReady so that we don't check if the deploy + task is being run before Gradle has figured it out. + */ + if (gradle.taskGraph.hasTask(":test:deploy")) { // fully qualified task name is needed + if (!project.hasProperty("robotClass")) { + throw new GradleException("Robot class not set. Pass a value in on the command line by adding -ProbotClass=.") + } else { + println "Creating JAR for robot ${project.robotClass}" + } + manifest GradleRIOPlugin.javaManifest(project.robotClass) + } + } from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } - manifest GradleRIOPlugin.javaManifest(ROBOT_CLASS) }