SlideShare a Scribd company logo
The Gangs of
Three
Ciao
ciao
Vai a fare
ciao ciao
Dr. Fabio Fumarola
Maven, Gradle and SBT
Java Project related questions
• How do we create a java project?
• How do we add dependencies?
• How do we create a runnable jar?
• How do we create a war?
• How do we execute tests?
2
Contents
• Maven
• Gradle
• Sbt
3
What is Maven?
• Apache Maven is a software project management.
• It is based on the concept of a Project Object Model
(POM)
• Maven can mange a project’s build, reporting a
documentation form a central piece of information
But it isn’t a mere build tool
4
Maven features
• Dependency System
• Multi-module builds
• Consistent project structure
• Consistent build model
• Plugin oriented
• Project generated sites
5
Advantages over Ant
• Eliminate complicate scripts
• All the functionality required to build your project,
i.e., clean, compile, copy, resources, install, deploy
• Cross Project Reuse – Ant has no convenient way to
reuse target across projects.
6
How Maven Works?
7
Maven keywords
• POM
• Archetype
• Artifact or dependency
• Plugin
• Goal
8
POM
• Unit of work in Maven
• It is an XML file that contains the information and
the configuration details used by Maven to build the
project
9
Archetype
• It is a template of a project with is combined with
some user input to produce a working Maven project
• There are hundreds of archetypes to help us get
started
– $ mvn –version
– $ mvn archetype:generate
-DgroupId=com.mycompany.app -DartifactId=my-app
-DarchetypeArtifactId=maven-archetype-quickstart
-DinteractiveMode=true
– $ mvn eclipse:eclipse
10
Artifact
• An artifact is a module obtained by another artifact
deployed to a maven repository
• Each artifact belongs to a group
• Each group can have more artifacts
11
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.6</version>
</dependency>
Goals and Plugins
• Are an extension of the standard maven lifecycles
steps.
– Clean, compile, test, package, install and deploy
• There are plugin to do other steps such as
12
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
[...]
</plugin> </plugins>
What is Gradle?
• Gradle is a general purpose build system
• It comes with a rich build description
• language (DSL) based on Groovy
• It supports ”build-by-convention” principle
• But it is very flexible and extensible
• It has built-in plug-ins for Java, Groovy, Scala, Web
• Groovy as a base language allows imperative
programming in the build file.
13
Advanced features
• Parallel unit test execution
• Dependency building
• Incremental build support
• Dynamic tasks and task rules
• Gradle daemon
14
Hello, Gradle
• Create a file build.gradle
task hello << {
println 'Hello World'
}
• Run $ gradle hello
• Edit the file as below
task hello << {
print 'Hello '
}
task world(dependsOn: hello) << {
println 'World!"
}
• Run $ gradle –q world
15
Build scripts are code
task upper << {
String someString = 'mY_nAmE'
println "Original: " + someString
println "Upper case: " + someString.toUpperCase()
}
- $gradle upper
4.times { counter ->
task "task$counter" << {
println "I'm task number $counter"
}
}
16
Gradle is Groovy that is Java
JAVA
import java.ioFile;
…
String parentDir = new File(“test.txt”).getAbsoluteFile()
.getParentPath();
Groovy
def parentDir = new File(“test.txt”).absoluteFile.parentPath
Gradle
parentDir = file(“test.txt”).absoluteFile.parentPath
17
Building a Java project
apply plugin: ‘java’
18
Gradle support all ant task
task hello << {
String greeting = "hello from Ant" ant.echo(message: greeting)
}
task list << {
def path = ant.path {
fileset(dir: 'libs', includes: '*.jar') }
path.list().each { println it }
}
task zip << {
ant.zip(destfile: 'archive.zip') {
fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java')
} } }
19
Overriding conventions
Version = 1.0
Group = ‘org.mygroup’
task release(dependsOn: assemble) << {
println 'We release now'
}
build.taskGraph.whenReady { taskGraph -> if
(taskGraph.hasTask(':release')) {
version = '1.0’
} else {
version = '1.0-SNAPSHOT’ }
} 20
Referencing files & file
collections• Groovy-like syntax:
File configFile = file('src/config.xml')
• Create a file collection from a bunch of files:
 FileCollection collection = files( 'src/file1.txt',
new File('src/file2.txt'), ['src/file3.txt', 'src/file4.txt'])
• Create a files collection by referencing project
properties:
 collection = files { srcDir.listFiles() }
• Operation on collections
def union = collection + files('src/file4.txt')
def different = collection - files('src/file3.txt')}
21
Using file collections as input
• Use a File object to specify the source directory.
compile { source = file('src/main/java') }
• Using a closure to specify the source files.
compile {
source = {
file(‘src’).listFiles()
.findAll { it.name.endsWith('.zip') }
.collect { zipTree(it) }
}
}
}
22
Copying files
• Using Gradle task type:
 task copyTask(type: Copy) {
from 'src/main/webapp‘
into 'build/explodedWar‘
include '**/*.jsp‘ exclude { details ->
details.file.name.endsWith('.html') &&
details.file.text.contains('staging')
}
}
23
Dependency management
24
Repository configuration
• Remote Repos
repositories {
mavenCentral()
mavenCentral name: 'multi-jar-repos', urls:
["http://repo.mycompany.com/jars1",
"http://repo.mycompany.com/jars1"]
}
• Local Repos
repositories {
flatDir name: 'localRepository',
dirs: 'lib' flatDir dirs: ['lib1', 'lib2']
} 25
Referencing dependencies
dependencies {
runtime files('libs/a.jar', 'libs/b.jar’)
runtime fileTree(dir: 'libs', includes: ['*.jar'])
}
dependencies {
compile 'org.springframework:spring-webmvc:3.0.0.RELEASE'
testCompile 'org.springframework:spring-test:3.0.0.RELEASE'
testCompile 'junit:junit:4.7'
}
26
Referencing dependencies
List groovy = ["org.codehaus.groovy:groovy-all:1.5.4@jar",
"commons-cli:commons-cli:1.0@jar",
"org.apache.ant:ant:1.7.0@jar"]
List hibernate = ['org.hibernate:hibernate:3.0.5@jar',
'somegroup:someorg:1.0@jar']
dependencies {
runtime groovy, hibernate
}
27
Plugins
28
Extending your build
• Any Gradle script can be a plug-in:
apply from: 'otherScript.gradle'
apply from: 'http://mycomp.com/otherScript.gradle’
• Use many of the standard or 3rd-party plug-ins:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'scala'
apply plugin: 'war'
29
Standard plugins
30
http://www.gradle.org/docs/current/userguide/standard_plugins.html
Example java and scala project
• http://www.gradle.org/docs/current/userguide/tutorial_j
• http://www.gradle.org/docs/current/userguide/scala_plu
• http://plugins.gradle.org/
31
Sbt
The interactive build tool
32
Sbt
• It is a tool to define task and then run them from the
shell
• To install on linux grab the
– rpm: https://dl.bintray.com/sbt/rpm/sbt-0.13.7.rpm
– deb: https://dl.bintray.com/sbt/rpm/sbt-0.13.7.deb
33
Starting with sbt
• It is based on the file build.sbt
• Create a directory hello_scala
• Edit a file and add
lazy val root = (project in file(".")).
settings(
name.:=("hello”),
version := "1.0",
scalaVersion := "2.11.4"
)
• Create an HelloWorld class
34
Project Structure
• Sbt is base on maven project structure
35
Running sbt
• It has a shell via $sbt
• Or we can run task in batch
– $ sbt clean compile "testOnly TestA TestB”
• It also support continuos delivery and run via
– > ~compile
– > ~run
36
Creating a project definition
• To create a project in the build.sbt file
lazy val root = (project in file(.)).
settings(
organization := "com.example",
version := "0.1.0",
scalaVersion := "2.11.4"
)
• The build.sbt define a Project which holds a list of
scala expression called settings
• Moreover a build.sbt can have vals, lazy vals and defs
37
SettingKey, TaskKey and InputKey
lazy val root = (project in file(".")).
settings(
name.:=("hello")
)
•.:= is a method that takes a parameter and return s
Setting[String]
lazy val root = (project in file(".")).
settings(
name := 42 // will not compile
)
•Does it run?
38
Types of key
• SettingKey[T]: a key for a value computed once (the
value is computed when loading the project, and
kept around).
• TaskKey[T]: a key for a value, called a task, that has
to be recomputed each time, potentially with side
effects.
• InputKey[T]: a key for a task that has command line
arguments as input. Check out Input Tasks for more
details.
• The built-in key are field of the object Keys
(http://www.scala-
sbt.org/0.13/sxr/sbt/Keys.scala.html) 39
Custom Keys
• Can be created with their:
– settingKey, taskKey and inputKey
lazy val hello = taskKey[Unit](“An example task”)
• A TaskKey[T] can be used to define task such as
compile or package.
40
Defining tasks and settings
• For example, to implement the hello task
lazy val hello = taskKey[Unit]("An example task”)
lazy val root = (project in file(".")).
settings(
hello := { println("Hello!") }
)
• Imports in build.sbt
import sbt._
import Process._
import Keys._
41
Adding library dependencies
val derby = "org.apache.derby" % "derby" % "10.4.1.3"
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0",
scalaVersion := "2.11.4"
)
lazy val root = (project in file(".")).
settings(commonSettings: _*).
settings(
name := "hello",
libraryDependencies += derby
)
42
Dependencies
• To add an unmanaged dependency there is the task
unmanagedBase := baseDirectory.value / "custom_lib”
• To add an managed dependency there is the task
libraryDependencies += groupID % artifactID % revision
• Or
libraryDependencies ++= Seq(
groupID % artifactID % revision,
groupID % otherID % otherRevision
)
43
Resolvers
• To add a resolver
1. resolvers += name at location
2. resolvers += Resolver.mavenLocal
3. resolvers ++= Seq(name1 at location1, name2 at
location2)
• Is it possible also to define if the dependency is for
test
libraryDependencies += "org.apache.derby" % "derby" %
"10.4.1.3" % Test
44
Plugins
• To declare a plugin add a directory project/Build.sbt
45

More Related Content

What's hot

Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
Zakaria El ktaoui
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
Kostas Saidis
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
José Paumard
 
Spring Boot
Spring BootSpring Boot
Spring Boot
Jaran Flaath
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
Mindfire Solutions
 
Percona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database SystemPercona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database System
Frederic Descamps
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
Taewan Kim
 
A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.
Subramanyam Vemala
 
makefiles tutorial
makefiles tutorialmakefiles tutorial
makefiles tutorial
vsubhashini
 
Introduction to helm
Introduction to helmIntroduction to helm
Introduction to helm
Jeeva Chelladhurai
 
Maven
MavenMaven
Maven
Emprovise
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
Sam Brannen
 
Rundeck: The missing tool
Rundeck: The missing toolRundeck: The missing tool
Rundeck: The missing tool
Artur Martins
 
Jenkins 101: Getting Started
Jenkins 101: Getting StartedJenkins 101: Getting Started
Jenkins 101: Getting Started
R Geoffrey Avery
 
Docker Tutorial.pdf
Docker Tutorial.pdfDocker Tutorial.pdf
Docker Tutorial.pdf
MuhammadYusuf767705
 
왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법
GeunCheolYeom
 
What's new in Java 11
What's new in Java 11What's new in Java 11
What's new in Java 11
Michel Schudel
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
Sandeep Chawla
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
ColCh
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
Tusharadri Sarkar
 

What's hot (20)

Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 
An Introduction to Gradle for Java Developers
An Introduction to Gradle for Java DevelopersAn Introduction to Gradle for Java Developers
An Introduction to Gradle for Java Developers
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Percona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database SystemPercona Live 2022 - The Evolution of a MySQL Database System
Percona Live 2022 - The Evolution of a MySQL Database System
 
Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실Cloud Native Java GraalVM 이상과 현실
Cloud Native Java GraalVM 이상과 현실
 
A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.A Java Microservices Spring Boot and Docker case study.
A Java Microservices Spring Boot and Docker case study.
 
makefiles tutorial
makefiles tutorialmakefiles tutorial
makefiles tutorial
 
Introduction to helm
Introduction to helmIntroduction to helm
Introduction to helm
 
Maven
MavenMaven
Maven
 
Spring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing SupportSpring 3.1 and MVC Testing Support
Spring 3.1 and MVC Testing Support
 
Rundeck: The missing tool
Rundeck: The missing toolRundeck: The missing tool
Rundeck: The missing tool
 
Jenkins 101: Getting Started
Jenkins 101: Getting StartedJenkins 101: Getting Started
Jenkins 101: Getting Started
 
Docker Tutorial.pdf
Docker Tutorial.pdfDocker Tutorial.pdf
Docker Tutorial.pdf
 
왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법왕초보를 위한 도커 사용법
왕초보를 위한 도커 사용법
 
What's new in Java 11
What's new in Java 11What's new in Java 11
What's new in Java 11
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 

Similar to An introduction to maven gradle and sbt

Gradle
GradleGradle
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
Mert Çalışkan
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
Ryan Cuprak
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
Bhagwat Kumar
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using ScalaNgoc Dao
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
Mert Çalışkan
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
Alkacon Software GmbH & Co. KG
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
Ryan Cuprak
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
Renat Bekbolatov
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
Kevin He
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
Jeevesh Pandey
 
How to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstackHow to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstack
Sławomir Kapłoński
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
Antoine Sabot-Durand
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
Virtual JBoss User Group
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
Sadayuki Furuhashi
 
tools cli java
tools cli javatools cli java
tools cli java
TiNguyn863920
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new buildIgor Khotin
 
cheat-sheets.pdf
cheat-sheets.pdfcheat-sheets.pdf
cheat-sheets.pdf
FabianaFCordeiro
 
Composer JSON kills make files
Composer JSON kills make filesComposer JSON kills make files
Composer JSON kills make files
ropsu
 

Similar to An introduction to maven gradle and sbt (20)

Gradle
GradleGradle
Gradle
 
Intelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest IstanbulIntelligent Projects with Maven - DevFest Istanbul
Intelligent Projects with Maven - DevFest Istanbul
 
Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]Faster java ee builds with gradle [con4921]
Faster java ee builds with gradle [con4921]
 
Gradle - Build system evolved
Gradle - Build system evolvedGradle - Build system evolved
Gradle - Build system evolved
 
How to start using Scala
How to start using ScalaHow to start using Scala
How to start using Scala
 
BMO - Intelligent Projects with Maven
BMO - Intelligent Projects with MavenBMO - Intelligent Projects with Maven
BMO - Intelligent Projects with Maven
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
Faster Java EE Builds with Gradle
Faster Java EE Builds with GradleFaster Java EE Builds with Gradle
Faster Java EE Builds with Gradle
 
SBT Concepts, part 2
SBT Concepts, part 2SBT Concepts, part 2
SBT Concepts, part 2
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
How to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstackHow to integrate_custom_openstack_services_with_devstack
How to integrate_custom_openstack_services_with_devstack
 
Apache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolboxApache DeltaSpike the CDI toolbox
Apache DeltaSpike the CDI toolbox
 
Apache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI ToolboxApache DeltaSpike: The CDI Toolbox
Apache DeltaSpike: The CDI Toolbox
 
Plugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGemsPlugin-based software design with Ruby and RubyGems
Plugin-based software design with Ruby and RubyGems
 
tools cli java
tools cli javatools cli java
tools cli java
 
Gradle - time for a new build
Gradle - time for a new buildGradle - time for a new build
Gradle - time for a new build
 
cheat-sheets.pdf
cheat-sheets.pdfcheat-sheets.pdf
cheat-sheets.pdf
 
Composer JSON kills make files
Composer JSON kills make filesComposer JSON kills make files
Composer JSON kills make files
 

More from Fabio Fumarola

11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2
Fabio Fumarola
 
11. From Hadoop to Spark 1:2
11. From Hadoop to Spark 1:211. From Hadoop to Spark 1:2
11. From Hadoop to Spark 1:2
Fabio Fumarola
 
10b. Graph Databases Lab
10b. Graph Databases Lab10b. Graph Databases Lab
10b. Graph Databases Lab
Fabio Fumarola
 
10. Graph Databases
10. Graph Databases10. Graph Databases
10. Graph Databases
Fabio Fumarola
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
Fabio Fumarola
 
9. Document Oriented Databases
9. Document Oriented Databases9. Document Oriented Databases
9. Document Oriented Databases
Fabio Fumarola
 
8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab
Fabio Fumarola
 
8a. How To Setup HBase with Docker
8a. How To Setup HBase with Docker8a. How To Setup HBase with Docker
8a. How To Setup HBase with Docker
Fabio Fumarola
 
8. column oriented databases
8. column oriented databases8. column oriented databases
8. column oriented databases
Fabio Fumarola
 
8. key value databases laboratory
8. key value databases laboratory 8. key value databases laboratory
8. key value databases laboratory
Fabio Fumarola
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
Fabio Fumarola
 
6 Data Modeling for NoSQL 2/2
6 Data Modeling for NoSQL 2/26 Data Modeling for NoSQL 2/2
6 Data Modeling for NoSQL 2/2
Fabio Fumarola
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
Fabio Fumarola
 
3 Git
3 Git3 Git
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
Fabio Fumarola
 
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
Fabio Fumarola
 
Scala and spark
Scala and sparkScala and spark
Scala and spark
Fabio Fumarola
 
Hbase an introduction
Hbase an introductionHbase an introduction
Hbase an introduction
Fabio Fumarola
 
Develop with linux containers and docker
Develop with linux containers and dockerDevelop with linux containers and docker
Develop with linux containers and docker
Fabio Fumarola
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
Fabio Fumarola
 

More from Fabio Fumarola (20)

11. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/211. From Hadoop to Spark 2/2
11. From Hadoop to Spark 2/2
 
11. From Hadoop to Spark 1:2
11. From Hadoop to Spark 1:211. From Hadoop to Spark 1:2
11. From Hadoop to Spark 1:2
 
10b. Graph Databases Lab
10b. Graph Databases Lab10b. Graph Databases Lab
10b. Graph Databases Lab
 
10. Graph Databases
10. Graph Databases10. Graph Databases
10. Graph Databases
 
9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab9b. Document-Oriented Databases lab
9b. Document-Oriented Databases lab
 
9. Document Oriented Databases
9. Document Oriented Databases9. Document Oriented Databases
9. Document Oriented Databases
 
8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab8b. Column Oriented Databases Lab
8b. Column Oriented Databases Lab
 
8a. How To Setup HBase with Docker
8a. How To Setup HBase with Docker8a. How To Setup HBase with Docker
8a. How To Setup HBase with Docker
 
8. column oriented databases
8. column oriented databases8. column oriented databases
8. column oriented databases
 
8. key value databases laboratory
8. key value databases laboratory 8. key value databases laboratory
8. key value databases laboratory
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
 
6 Data Modeling for NoSQL 2/2
6 Data Modeling for NoSQL 2/26 Data Modeling for NoSQL 2/2
6 Data Modeling for NoSQL 2/2
 
5 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/25 Data Modeling for NoSQL 1/2
5 Data Modeling for NoSQL 1/2
 
3 Git
3 Git3 Git
3 Git
 
2 Linux Container and Docker
2 Linux Container and Docker2 Linux Container and Docker
2 Linux Container and Docker
 
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
1. Introduction to the Course "Designing Data Bases with Advanced Data Models...
 
Scala and spark
Scala and sparkScala and spark
Scala and spark
 
Hbase an introduction
Hbase an introductionHbase an introduction
Hbase an introduction
 
Develop with linux containers and docker
Develop with linux containers and dockerDevelop with linux containers and docker
Develop with linux containers and docker
 
Linux containers and docker
Linux containers and dockerLinux containers and docker
Linux containers and docker
 

Recently uploaded

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
seandesed
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 

Recently uploaded (20)

DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 

An introduction to maven gradle and sbt

  • 1. The Gangs of Three Ciao ciao Vai a fare ciao ciao Dr. Fabio Fumarola Maven, Gradle and SBT
  • 2. Java Project related questions • How do we create a java project? • How do we add dependencies? • How do we create a runnable jar? • How do we create a war? • How do we execute tests? 2
  • 4. What is Maven? • Apache Maven is a software project management. • It is based on the concept of a Project Object Model (POM) • Maven can mange a project’s build, reporting a documentation form a central piece of information But it isn’t a mere build tool 4
  • 5. Maven features • Dependency System • Multi-module builds • Consistent project structure • Consistent build model • Plugin oriented • Project generated sites 5
  • 6. Advantages over Ant • Eliminate complicate scripts • All the functionality required to build your project, i.e., clean, compile, copy, resources, install, deploy • Cross Project Reuse – Ant has no convenient way to reuse target across projects. 6
  • 8. Maven keywords • POM • Archetype • Artifact or dependency • Plugin • Goal 8
  • 9. POM • Unit of work in Maven • It is an XML file that contains the information and the configuration details used by Maven to build the project 9
  • 10. Archetype • It is a template of a project with is combined with some user input to produce a working Maven project • There are hundreds of archetypes to help us get started – $ mvn –version – $ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=true – $ mvn eclipse:eclipse 10
  • 11. Artifact • An artifact is a module obtained by another artifact deployed to a maven repository • Each artifact belongs to a group • Each group can have more artifacts 11 <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.6</version> </dependency>
  • 12. Goals and Plugins • Are an extension of the standard maven lifecycles steps. – Clean, compile, test, package, install and deploy • There are plugin to do other steps such as 12 <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.3</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> [...] </plugin> </plugins>
  • 13. What is Gradle? • Gradle is a general purpose build system • It comes with a rich build description • language (DSL) based on Groovy • It supports ”build-by-convention” principle • But it is very flexible and extensible • It has built-in plug-ins for Java, Groovy, Scala, Web • Groovy as a base language allows imperative programming in the build file. 13
  • 14. Advanced features • Parallel unit test execution • Dependency building • Incremental build support • Dynamic tasks and task rules • Gradle daemon 14
  • 15. Hello, Gradle • Create a file build.gradle task hello << { println 'Hello World' } • Run $ gradle hello • Edit the file as below task hello << { print 'Hello ' } task world(dependsOn: hello) << { println 'World!" } • Run $ gradle –q world 15
  • 16. Build scripts are code task upper << { String someString = 'mY_nAmE' println "Original: " + someString println "Upper case: " + someString.toUpperCase() } - $gradle upper 4.times { counter -> task "task$counter" << { println "I'm task number $counter" } } 16
  • 17. Gradle is Groovy that is Java JAVA import java.ioFile; … String parentDir = new File(“test.txt”).getAbsoluteFile() .getParentPath(); Groovy def parentDir = new File(“test.txt”).absoluteFile.parentPath Gradle parentDir = file(“test.txt”).absoluteFile.parentPath 17
  • 18. Building a Java project apply plugin: ‘java’ 18
  • 19. Gradle support all ant task task hello << { String greeting = "hello from Ant" ant.echo(message: greeting) } task list << { def path = ant.path { fileset(dir: 'libs', includes: '*.jar') } path.list().each { println it } } task zip << { ant.zip(destfile: 'archive.zip') { fileset(dir: 'src') { include(name: '**.xml') exclude(name: '**.java') } } } 19
  • 20. Overriding conventions Version = 1.0 Group = ‘org.mygroup’ task release(dependsOn: assemble) << { println 'We release now' } build.taskGraph.whenReady { taskGraph -> if (taskGraph.hasTask(':release')) { version = '1.0’ } else { version = '1.0-SNAPSHOT’ } } 20
  • 21. Referencing files & file collections• Groovy-like syntax: File configFile = file('src/config.xml') • Create a file collection from a bunch of files:  FileCollection collection = files( 'src/file1.txt', new File('src/file2.txt'), ['src/file3.txt', 'src/file4.txt']) • Create a files collection by referencing project properties:  collection = files { srcDir.listFiles() } • Operation on collections def union = collection + files('src/file4.txt') def different = collection - files('src/file3.txt')} 21
  • 22. Using file collections as input • Use a File object to specify the source directory. compile { source = file('src/main/java') } • Using a closure to specify the source files. compile { source = { file(‘src’).listFiles() .findAll { it.name.endsWith('.zip') } .collect { zipTree(it) } } } } 22
  • 23. Copying files • Using Gradle task type:  task copyTask(type: Copy) { from 'src/main/webapp‘ into 'build/explodedWar‘ include '**/*.jsp‘ exclude { details -> details.file.name.endsWith('.html') && details.file.text.contains('staging') } } 23
  • 25. Repository configuration • Remote Repos repositories { mavenCentral() mavenCentral name: 'multi-jar-repos', urls: ["http://repo.mycompany.com/jars1", "http://repo.mycompany.com/jars1"] } • Local Repos repositories { flatDir name: 'localRepository', dirs: 'lib' flatDir dirs: ['lib1', 'lib2'] } 25
  • 26. Referencing dependencies dependencies { runtime files('libs/a.jar', 'libs/b.jar’) runtime fileTree(dir: 'libs', includes: ['*.jar']) } dependencies { compile 'org.springframework:spring-webmvc:3.0.0.RELEASE' testCompile 'org.springframework:spring-test:3.0.0.RELEASE' testCompile 'junit:junit:4.7' } 26
  • 27. Referencing dependencies List groovy = ["org.codehaus.groovy:groovy-all:1.5.4@jar", "commons-cli:commons-cli:1.0@jar", "org.apache.ant:ant:1.7.0@jar"] List hibernate = ['org.hibernate:hibernate:3.0.5@jar', 'somegroup:someorg:1.0@jar'] dependencies { runtime groovy, hibernate } 27
  • 29. Extending your build • Any Gradle script can be a plug-in: apply from: 'otherScript.gradle' apply from: 'http://mycomp.com/otherScript.gradle’ • Use many of the standard or 3rd-party plug-ins: apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'scala' apply plugin: 'war' 29
  • 31. Example java and scala project • http://www.gradle.org/docs/current/userguide/tutorial_j • http://www.gradle.org/docs/current/userguide/scala_plu • http://plugins.gradle.org/ 31
  • 33. Sbt • It is a tool to define task and then run them from the shell • To install on linux grab the – rpm: https://dl.bintray.com/sbt/rpm/sbt-0.13.7.rpm – deb: https://dl.bintray.com/sbt/rpm/sbt-0.13.7.deb 33
  • 34. Starting with sbt • It is based on the file build.sbt • Create a directory hello_scala • Edit a file and add lazy val root = (project in file(".")). settings( name.:=("hello”), version := "1.0", scalaVersion := "2.11.4" ) • Create an HelloWorld class 34
  • 35. Project Structure • Sbt is base on maven project structure 35
  • 36. Running sbt • It has a shell via $sbt • Or we can run task in batch – $ sbt clean compile "testOnly TestA TestB” • It also support continuos delivery and run via – > ~compile – > ~run 36
  • 37. Creating a project definition • To create a project in the build.sbt file lazy val root = (project in file(.)). settings( organization := "com.example", version := "0.1.0", scalaVersion := "2.11.4" ) • The build.sbt define a Project which holds a list of scala expression called settings • Moreover a build.sbt can have vals, lazy vals and defs 37
  • 38. SettingKey, TaskKey and InputKey lazy val root = (project in file(".")). settings( name.:=("hello") ) •.:= is a method that takes a parameter and return s Setting[String] lazy val root = (project in file(".")). settings( name := 42 // will not compile ) •Does it run? 38
  • 39. Types of key • SettingKey[T]: a key for a value computed once (the value is computed when loading the project, and kept around). • TaskKey[T]: a key for a value, called a task, that has to be recomputed each time, potentially with side effects. • InputKey[T]: a key for a task that has command line arguments as input. Check out Input Tasks for more details. • The built-in key are field of the object Keys (http://www.scala- sbt.org/0.13/sxr/sbt/Keys.scala.html) 39
  • 40. Custom Keys • Can be created with their: – settingKey, taskKey and inputKey lazy val hello = taskKey[Unit](“An example task”) • A TaskKey[T] can be used to define task such as compile or package. 40
  • 41. Defining tasks and settings • For example, to implement the hello task lazy val hello = taskKey[Unit]("An example task”) lazy val root = (project in file(".")). settings( hello := { println("Hello!") } ) • Imports in build.sbt import sbt._ import Process._ import Keys._ 41
  • 42. Adding library dependencies val derby = "org.apache.derby" % "derby" % "10.4.1.3" lazy val commonSettings = Seq( organization := "com.example", version := "0.1.0", scalaVersion := "2.11.4" ) lazy val root = (project in file(".")). settings(commonSettings: _*). settings( name := "hello", libraryDependencies += derby ) 42
  • 43. Dependencies • To add an unmanaged dependency there is the task unmanagedBase := baseDirectory.value / "custom_lib” • To add an managed dependency there is the task libraryDependencies += groupID % artifactID % revision • Or libraryDependencies ++= Seq( groupID % artifactID % revision, groupID % otherID % otherRevision ) 43
  • 44. Resolvers • To add a resolver 1. resolvers += name at location 2. resolvers += Resolver.mavenLocal 3. resolvers ++= Seq(name1 at location1, name2 at location2) • Is it possible also to define if the dependency is for test libraryDependencies += "org.apache.derby" % "derby" % "10.4.1.3" % Test 44
  • 45. Plugins • To declare a plugin add a directory project/Build.sbt 45

Editor's Notes

  1. def times(i: Int)(f: (Int) =&amp;gt; Void)