Intro to Gradle for FRC

Intro to Gradle for FRC

Delivered at StuySplash for FIRST Robotics Challenge Team 694.

3906b007e5c4150115e319a01d2f4ab8?s=128

Jeanne Boyarsky

December 12, 2019
Tweet

Transcript

  1. 1.

    @jeanneboyarsky 1 Intro to Gradle For FRC Jeanne Boyarsky Saturday

    December 14, 2019 StuySplash speakerdeck.com/boyarsky
  2. 2.

    @jeanneboyarsky About Me • 11 year FRC volunteer • Professional

    Programmer • Java Champion (about 300 in the world) • Build Tool Expert • And… 2
  3. 5.

    @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 5
  4. 7.

    @jeanneboyarsky “Java is Still Free” • Free for non-production use

    • For Prod use 20 minute version: https://medium.com/@javachampions/java- is-still-free-2-0-0-6b9aa8d6d244 7
  5. 8.

    @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 8
  6. 9.

    @jeanneboyarsky What is a Build Tool? • Automated • Creates

    executable • Reproduceable • Codified 9
  7. 10.

    @jeanneboyarsky Find the build tool? 10 Saw? Band Saw? CNC

    Machine? x Not automated x Automation != Electricity ✔Programming x But doesn’t create executable
  8. 11.

    @jeanneboyarsky Happy Birthday Make • 1976 • C • Makefile

    • Compiles code • Adds libraries • Can call OS commands 11
  9. 13.

    @jeanneboyarsky Quick Comparison 13 Ant Maven Gradle Released 2000 2004

    2007 Build file build.xml pom.xml build.gradle Language XML XML Groovy Dependency mgmt? Not native Yes Yes
  10. 14.

    @jeanneboyarsky FRC Timeline • 2004-2008 - IFI • 2009-2014 -

    cRIO with Java • Java 1.4 Mobile • 2015-? - RoboRIO with Java • Multi core • Current versions of Java 14
  11. 16.

    @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 16
  12. 18.

    @jeanneboyarsky Benefits • Less code to build • Fewer decisions

    to make • Faster to switch between teams • Easier to work on open source 18
  13. 19.

    @jeanneboyarsky Phases 19 Initialization Counts gradle projects (1 Robot) Configuration

    Parses the build script Execution Determines which tasks to execute and does so
  14. 22.
  15. 23.

    @jeanneboyarsky Key Gradle Files 23 File Description build.gradle The build

    script gradlew Gradle wrapper so can run without installing Gradle on Mac/Linux gradlew Same for Windows settings.gradle Sets projects specific config before build runs
  16. 24.

    @jeanneboyarsky Gradle Directories 24 Directory Description .gradle Cache .wpilib FRC

    specific. Contains metadata. Ex: build year, team number vendordeps JSON files with locations for some dependencies
  17. 25.

    @jeanneboyarsky JAR • Java Archive • Like zip file •

    Contains compiled code • You depend on these libraries 25
  18. 26.

    @jeanneboyarsky Dependency • Often hosted on binary repository • ex:

    Maven Central • Some FRC plugins not in Central • vendordeps! 26
  19. 27.

    @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 27
  20. 29.

    @jeanneboyarsky From command palette > Executing task: ./gradlew deploy -

    PteamNumber=694 --offline - Dorg.gradle.java.home="/Library/Java/ JavaVirtualMachines/jdk-11.0.2.jdk/ Contents/Home" < 29 -P = project property -D = system property
  21. 40.

    @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 40
  22. 44.

    @jeanneboyarsky Java -> Groovy int lastYear = 2017; int year

    = 2018 def nextYear = 2019 44 Can use Java syntax Without semicolon or type
  23. 45.

    @jeanneboyarsky Strings def city = 'SF' println 'Here: $city' println

    "Here: $city" println "In ${city.class}" 45 Java String GString Here: $city Here: SF In class java.lang.String
  24. 46.

    @jeanneboyarsky Multi Line String def name = 'Jeanne' def text

    = """ Name ______ $name """ println text 46 Coming soon to Java with new syntax Name ______ Jeanne
  25. 47.

    @jeanneboyarsky What does this print? def name = 'Jeanne' def

    text = ’’’ Name ______ $name ’’’ println text 47 Name ______ $name
  26. 49.

    @jeanneboyarsky == vs equals() def monday ='monday' def nextMonday =

    new String('monday') def tuesday ='tuesday' println monday == null println null == monday println monday == tuesday println monday == nextMonday 49 Java Syntax True!
  27. 50.

    @jeanneboyarsky What is the Truth? 50 Value Result Null FALSE

    Empty String FALSE Empty List FALSE 1 Character String TRUE
  28. 52.

    @jeanneboyarsky Optional Parens def ch = 'abc'.charAt 1 println ch

    52 Optional when no ambiguity Ambiguity: * Zero params * Within println
  29. 53.

    @jeanneboyarsky ArrayList++ 53 def list = ['cookie', 'chocolate’] list <<

    'candy' println list.getClass() class java.util.ArrayList println list[1] chocolate ArrayList does what now?
  30. 54.

    @jeanneboyarsky ArrayList++ 54 println list [cookie, chocolate, candy] println list[-1]

    candy println list.min() candy list.sort() println list [candy, chocolate, cookie]
  31. 55.

    @jeanneboyarsky Functions incrementBy = 4; def add(num) { num +

    incrementBy } println add(2) 55 no def types optional return optional
  32. 57.

    @jeanneboyarsky Named Params def config = new SelectorConfiguration( name: ‘selector',

    description: ‘packages', ) 57 Only the default constructor exists!
  33. 58.

    @jeanneboyarsky Alfred vs Edwin File file = new File("src/main/java/frc/robot/RobotMap.java") System.out.println("=========================")

    if(file.text.contains('ROBOT_NAME = "Alfred"')) { System.out.println("Built to ALFRED!!!") } else if(file.text.contains('ROBOT_NAME = "Edwin"')) { System.out.println("Built to EDWIN!!!") } else { System.out.println("[ATTENTION] Look at RobotMap and make sure you have robot name set!") throw new IllegalStateException("Robot Name Not Found"); } System.out.println("=========================") 58