程序代写代做代考 Hive Java jvm chain L3. Agile Software Development (II)
L3. Agile Software Development (II)
Introduction to Gradle
Dr A Boronat
Continuous Delivery Gradle
Sprint 1:
• Goal: test next week – Tuesday 18 October 16:00-18:00 (CW 301)
• Schedule: calendar on Blackboard
• Progress: sprint backlog
• Groovy should be completed by now
• STS ready
• Exercises: solutions
2 / 20
https://blackboard.le.ac.uk/webapps/blackboard/content/listContentEditable.jsp?content_id=_1290722_1&course_id=_1807_1&mode=reset
https://github.com/uol-inf/CO2006-16-17/blob/master/sprint1/Groovy_exercises/src/solution/exercises_solutions.groovy
Continuous Delivery Gradle
Problem 1
Goal
• Software release: software that is developed and tested, i.e. our goal
• Build: software that is compiled and assembled (a jar file), intermediate
goal to achieve a release
Problems in release management
• Does the code compile?
• Does the code pass the tests? (unit tests)
• Does the code meet the business requirements? (functionality)
• Does the code meet the quality criteria? (performance, security, etc.)
Solution:
Build automation
3 / 20
4 / 20
Continuous Delivery Gradle
Problem 2
Dependency Hell
• Many dependencies
• Long chains of
dependencies
• Conflicting dependencies:
when different versions
cannot be simultaneously
installed
• Circular dependencies
Solution
Dependency management
JasperReports
5 / 20
https://en.wikipedia.org/wiki/Dependency_hell
Continuous Delivery Gradle
Gradle: a DSL for Build Automation
Features
• Provides a DSL to define a continuous delivery pipeline based on Groovy
• Build automation
• Declarative builds and build-by-convention
• Scalable
• Dependency Management
• Dependencies between projects, to local libraries, to remote repositories
6 / 20
https://docs.gradle.org/current/userguide/overview.html#sec:special_feature_of_gradle
http://www.groovy-lang.org
Continuous Delivery Gradle
Basic Terminology
• A build consists of one or more projects
• A project is a product to be built or a process to
be carried out
Ex: a library JAR or a web application
Ex: deploying your application to staging or
production environments
• A task is an atomic piece of work which a build
performs
Ex: compiling some classes, creating a JAR,
generating Javadoc, or publishing some archives to
a repository
7 / 20
Continuous Delivery Gradle
Gradle: Basic Tasks
• a task
task TaskA
TaskA.description = “task A”
• writing actions
TaskA.doLast { println “task A” }
TaskA << { println "task A" }
TaskA.doFirst { println "at the start of task A" }
• writing tasks as closures
task TaskA {
description "task A"
doLast { println "taskA" }
}
• to execute a task
./ gradlew TaskA
• to show all tasks available
./ gradlew tasks (--all)
8 / 20
Continuous Delivery Gradle
Gradle: Tasks Dependencies
• TaskA can execute only if TaskB is executed:
task TaskA
task TaskB
TaskA.dependsOn TaskB
• equivalently:
task TaskA {
dependsOn TaskB
}
task TaskB
• equivalently:
task TaskA
task TaskB
TaskB.finalizedBy TaskA
9 / 20
Continuous Delivery Gradle
Gradle: Properties
• local variables
def version = "1.0"
task TaskA {
description = "task A - version $version"
}
• global variables
project.ext.version = "1.0"
task TaskA {
description = "task A - version $version"
}
10 / 20
Continuous Delivery Gradle
Build Lifecycle
Initialization
• Determines the projects that will be involved in the build
• Creates a Project instance for each of these projects
Configuration
• Project objects are configured: properties
• Actions are not executed
Execution
• Determines the subset of the tasks to be executed (by the
task name arguments passed to the Gradle command and
the current directory)
• Gradle then executes the actions in each of the selected
tasks. 11 / 20
Continuous Delivery Gradle
Gradle: Typed Tasks
• Tasks that are predefined and can be reused:
https://docs.gradle.org/current/dsl
• copying files
task copyFiles(type: Copy) {
from ’source ’
into ’target ’
}
• excluding some files
task copyFiles(type: Copy) {
from ’source ’
into ’target ’
exclude ’file1 ’, ’file2 ’
}
12 / 20
https://docs.gradle.org/current/dsl
Continuous Delivery Gradle
Plugins
A Gradle plugin is an extension to Gradle which configures your project in
some way, typically by adding some pre-configured tasks which together
do something useful.
Plugins
• Java plugin
• Eclipse plugin
• Application plugin
13 / 20
https://docs.gradle.org/current/userguide/plugins.html
https://docs.gradle.org/current/userguide/java_plugin.html
https://docs.gradle.org/current/userguide/eclipse_plugin.html
https://docs.gradle.org/current/userguide/application_plugin.html
Continuous Delivery Gradle
Java Plugin
Java plugin
• tasks: compile, unit test, bundle into a JAR file
• source set: group of source files which are compiled and executed together
E.g. main, test
Example:
apply plugin: ’java ’
How to use it:
./ gradlew build
./ gradle test
14 / 20
https://docs.gradle.org/current/userguide/java_plugin.html
Continuous Delivery Gradle
Eclipse Plugin
Eclipse plugin: to generate files that are used by the Eclipse IDE
Example:
apply plugin: ’eclipse ’
How to use it:
./ gradlew cleanEclipse
./ gradlew eclipse
15 / 20
https://docs.gradle.org/current/userguide/eclipse_plugin.html
Continuous Delivery Gradle
Application Plugin
Application plugin: to create an executable JVM application
E.g. java console applications
Example:
apply plugin: ’application ’
mainClassName = ’package.ClassName ’
How to use it:
./ gradlew run
16 / 20
https://docs.gradle.org/current/userguide/application_plugin.html
Continuous Delivery Gradle
Project dependencies
Dependencies
• other projects
• external libraries
• internal libraries
Repositories
• where libraries are stored
repositories {
mavenCentral ()
}
• using dependencies from Maven Central
dependencies {
compile ’group:artifactId:version ’
}
17 / 20
http://search.maven.org
Continuous Delivery Gradle
Goals for this week
TODO list (sprint backlog) on Blackboard:
◻ Gradle: video and exercises
1 exercise 1
2 exercise 2
◻ Revise for the test (Tuesday 18 October 16:00-18:00 in CW 301): a mock
test will be available soon
18 / 20
https://blackboard.le.ac.uk/webapps/blackboard/content/listContentEditable.jsp?content_id=_1413983_1&course_id=_1807_1
https://github.com/uol-inf/CO2006-16-17/blob/master/sprint1/Gradle_ex01/readme.md
https://github.com/uol-inf/CO2006-16-17/blob/master/sprint1/Gradle_ex02/readme.md
Continuous Delivery Gradle
Feedback
Exercises
• solutions to be released next Monday
• surgery session on Monday 14:00-15:00 in KE LT3
• laboratory session next Tuesday 16:00-18:00 to discuss any questions you
may have about the exercises
• you do not need to attend the whole session if you don’t have questions
I’m stuck...
• DO NOT wait until Monday
• ASK in the discussion forum on Blackboard
19 / 20
20 / 20
Continuous Delivery
Gradle