Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Gradle for FRC

Intro to Gradle for FRC

Delivered at StuySplash for FIRST Robotics Challenge Team 694.

Jeanne Boyarsky

December 12, 2019
Tweet

More Decks by Jeanne Boyarsky

Other Decks in Education

Transcript

  1. @jeanneboyarsky 1 Intro to Gradle For FRC Jeanne Boyarsky Saturday

    December 14, 2019 StuySplash speakerdeck.com/boyarsky
  2. @jeanneboyarsky About Me • 11 year FRC volunteer • Professional

    Programmer • Java Champion (about 300 in the world) • Build Tool Expert • And… 2
  3. @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 5
  4. @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. @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 8
  6. @jeanneboyarsky What is a Build Tool? • Automated • Creates

    executable • Reproduceable • Codified 9
  7. @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. @jeanneboyarsky Happy Birthday Make • 1976 • C • Makefile

    • Compiles code • Adds libraries • Can call OS commands 11
  9. @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. @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. @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 16
  12. @jeanneboyarsky Benefits • Less code to build • Fewer decisions

    to make • Faster to switch between teams • Easier to work on open source 18
  13. @jeanneboyarsky Phases 19 Initialization Counts gradle projects (1 Robot) Configuration

    Parses the build script Execution Determines which tasks to execute and does so
  14. @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
  15. @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
  16. @jeanneboyarsky JAR • Java Archive • Like zip file •

    Contains compiled code • You depend on these libraries 25
  17. @jeanneboyarsky Dependency • Often hosted on binary repository • ex:

    Maven Central • Some FRC plugins not in Central • vendordeps! 26
  18. @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 27
  19. @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
  20. @jeanneboyarsky Agenda • Quick Java PSA • Intro to Build

    Tools • Intro to Gradle • Using Gradle for FRC • More on Groovy/Gradle 40
  21. @jeanneboyarsky Java -> Groovy int lastYear = 2017; int year

    = 2018 def nextYear = 2019 44 Can use Java syntax Without semicolon or type
  22. @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
  23. @jeanneboyarsky Multi Line String def name = 'Jeanne' def text

    = """ Name ______ $name """ println text 46 Coming soon to Java with new syntax Name ______ Jeanne
  24. @jeanneboyarsky What does this print? def name = 'Jeanne' def

    text = ’’’ Name ______ $name ’’’ println text 47 Name ______ $name
  25. @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!
  26. @jeanneboyarsky What is the Truth? 50 Value Result Null FALSE

    Empty String FALSE Empty List FALSE 1 Character String TRUE
  27. @jeanneboyarsky Optional Parens def ch = 'abc'.charAt 1 println ch

    52 Optional when no ambiguity Ambiguity: * Zero params * Within println
  28. @jeanneboyarsky ArrayList++ 53 def list = ['cookie', 'chocolate’] list <<

    'candy' println list.getClass() class java.util.ArrayList println list[1] chocolate ArrayList does what now?
  29. @jeanneboyarsky ArrayList++ 54 println list [cookie, chocolate, candy] println list[-1]

    candy println list.min() candy list.sort() println list [candy, chocolate, cookie]
  30. @jeanneboyarsky Functions incrementBy = 4; def add(num) { num +

    incrementBy } println add(2) 55 no def types optional return optional
  31. @jeanneboyarsky Named Params def config = new SelectorConfiguration( name: ‘selector',

    description: ‘packages', ) 57 Only the default constructor exists!
  32. @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