GRADLE 4 - JUG · PDF fileAndroid • Gradle tasks of Android plugin will become cacheable
Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get...
Transcript of Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get...
![Page 1: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/1.jpg)
CSE 403Software Engineering
Spring 2020
Build systems
May 6, 2020
![Page 2: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/2.jpg)
Recap: The Joel Test
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers?11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
![Page 3: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/3.jpg)
Recap: The Joel Test (20 years later)
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds? Do you use CI (clean master branch)?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers? Do you do automated testing ANDdo you have testers on your team?
11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
![Page 4: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/4.jpg)
Recap: The Joel Test (20 years later)
1. Do you use source control?2. Can you make a build [+ release] in one step?3. Do you make daily builds? Do you use CI (clean master branch)?4. Do you have a bug database?5. Do you fix bugs before writing new code?6. Do you have an up-to-date schedule?7. Do you have a spec?8. Do programmers have quiet working conditions?9. Do you use the best tools money can buy?
10. Do you have testers? Do you do automated testing ANDdo you have testers on your team?
11. Do new candidates write code during their interview?12. Do you do hallway usability testing?
403 requires
![Page 5: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/5.jpg)
Build systems● What is a build system?● Best practices● Gradle live demo
Today
![Page 6: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/6.jpg)
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What does a developer do?
Which of these tasks should be handled manually?
![Page 7: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/7.jpg)
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What does a developer do?
Which of these tasks should be handled manually?NONE!
![Page 8: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/8.jpg)
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
How to automate these tasks?
Orchestrate tasks with a build system!
![Page 9: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/9.jpg)
● Get the source code● Install dependencies● Compile the code● Run static analysis● Generate documentation● Run tests● Create artifacts for customers● Ship!
What is a build system (build tool)?
A tool for automating software engineering tasks:
![Page 10: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/10.jpg)
Build systems: tasks
Tasks are code!● Should be checked into version control● Should be code-reviewed● Should be tested
![Page 11: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/11.jpg)
Build systems: dependencies between tasks
Example code and corresponding tests:
> ls src/
Lib.java LibTest.java Main.java SystemTest.java
![Page 12: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/12.jpg)
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
What are the dependencies between these tasks?
![Page 13: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/13.jpg)
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
![Page 14: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/14.jpg)
compileMain
compileLib
run libtest
run systemtest
Build systems: dependencies between tasks
In what order should we run these tasks?
![Page 15: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/15.jpg)
Large projects may have thousands of task dependencies● Dependencies between tasks form a directed acyclic graph.
Build systems: determining task order
![Page 16: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/16.jpg)
Large projects may have thousands of task dependencies● Dependencies between tasks form a directed acyclic graph.
Topological sort● Order nodes such that all dependencies are satisfied● Implemented by computing indegree
(number of incoming edges) for each node
Build systems: determining task order
![Page 17: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/17.jpg)
compileMain
compileLib
run libtest
run systemtest
Build systems: topological sort
What’s the indegree of each node?
![Page 18: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/18.jpg)
compileMain
compileLib
run libtest
run systemtest
0
0
1
3
Build systems: topological sort
![Page 19: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/19.jpg)
compileMain
compileLib
run libtest
run systemtest
0
0
0
2
Build systems: topological sort
![Page 20: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/20.jpg)
compileMain
compileLib
run libtest
run systemtest
0
0
0
1
Build systems: topological sort
![Page 21: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/21.jpg)
compileMain
compileLib
run libtest
run systemtest
0
0
0
0
Build systems: topological sort
![Page 22: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/22.jpg)
compileMain
compileLib
run libtest
run systemtest
0
0
0
0
Build systems: topological sort
![Page 23: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/23.jpg)
compileMain
compileLib
run libtest
run systemtest
Valid sorts:
1. compile Lib, run lib test, compile Main, run system test
2. compile Main, compile Lib, run lib test, run system test
3. compile Lib, compile Main, run lib test, run system test
Build systems: topological sort
Which of these sorts is preferable?
![Page 24: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/24.jpg)
compileMain
compileLib
run libtest
run systemtest
Valid sorts:
1. compile Lib, run lib test, compile Main, run system test
2. compile Main, compile Lib, run lib test, run system test
3. compile Lib, compile Main, run lib test, run system test
Build systems: topological sort
Which of these sorts is preferable?
![Page 25: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/25.jpg)
Build systems: examples
gradle
Open-source successor to ant and maven● Groovy/Kotlin DSL (vs. xml)● Many defaults for (maven) conventions
bazel
Open-source version of Google’s internal build tool (blaze)
![Page 26: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/26.jpg)
Example task: gradle
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }}
![Page 27: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/27.jpg)
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }} explicitly specified
dependencies
Example task: gradle
![Page 28: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/28.jpg)
task reformat(type: Exec, dependsOn: getCodeFormatScripts, group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip onlyIf { !project.name.is('jdk8') && !project.name.is('checker-qual') } executable 'python' doFirst { args += "${formatScriptsHome}/run-google-java-format.py" args += "--aosp" // 4 space indentation args += getJavaFilesToFormat(project.name) }} Actual code (no xml)!
Example task: gradle
In many cases, following conventions andusing built-in tasks is sufficient to get started!
![Page 29: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/29.jpg)
Best practices
● Automate everything (one-step build)!● Always use a build tool.● Use CI to build and test your code on every commit.● Don’t depend on anything that’s not in the build file (hermetic)!● Don’t break the build
![Page 30: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/30.jpg)
Live demo: Build systems
Set up:1. Two clones of the basic-stats repo (cloned from Bitbucket).2. Goal: migrate from Ant to Gradle.
Two scenarios:1. Bad: Breaking the build on master2. Good: New hermetic build on a branch
![Page 31: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/31.jpg)
Live demo: Breaking the build
René breaking the build on master
Kaushal making a small change
![Page 32: Spring 2020 Software Engineering Build systems …rjust/courses/2020...Today Gradle live demo Get the source code Install dependencies Compile the code Run static analysis Generate](https://reader033.fdocuments.in/reader033/viewer/2022060314/5f0ba60a7e708231d43189de/html5/thumbnails/32.jpg)
Live demo: New hermetic build
● Development on a branch● Backward compatibility● Testing and code review