View
457
Download
2
Category
Preview:
DESCRIPTION
Javaone - Gradle: Harder, Better, Stronger, Faster
Citation preview
ANDRES ALMIRAY IX-CHEL RUIZ @AALMIRAY @IXCHELRUIZ
HARDER, BETTER,
STRONGER, FASTER
WHAT
Gradle is a build tool designed to take advantage of conventions over (not instead) configuration, while staying flexible enough to be customized to the needs of a particular project. In other words, the build tool bends to the project’s will, not the other way around.
Follows the Maven conventions. Expressive : Prefers a DSL for describing what needs to be done. Extensible : Has a growing an thriving plugin ecosystem. Productive : Fosters fast and reproducible builds. Convenient : It’s CI friendly (gradle wrapper).
WHY
RebelLabs © ZeroTurnaround
RebelLabs © ZeroTurnaround
Caching of task input and outputs Richer, configurable lifecycle The Gradle deamon The Gradle wrapper Multi-project builds are hassle free Plugin development is more intuitive Better documentation overall
HOW
$ curl -s get.gvmtool.net | bash $ gvm install gradle
.!
├── build.gradle!
├── pom.xml!
└── src!
├── main!
│ └── java!
│ └── sample!
│ └── Foo.java!
└── test!
└── java!
└── sample!
└── FooTest.java!
<project xmlns="http://maven.apache.org/POM/4.0.0"!
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"!
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">!
<modelVersion>4.0.0</modelVersion>!
<groupId>com.acme</groupId>!
<artifactId>sample</artifactId>!
<packaging>jar</packaging>!
<version>0.0.0-SNAPSHOT</version>!
!
<dependencies>!
<dependency>!
<groupId>junit</groupId>!
<artifactId>junit</artifactId>!
<version>4.11</version>!
<scope>test</scope>!
</dependency>!
</dependencies>!
</project>!
😐
apply plugin: 'java'!
apply plugin: 'maven-publish'!
!
version = '0.0.0-SNAPSHOT'!
group = 'com.acme'!
!
repositories {!
jcenter()!
}!
!
dependencies {!
testCompile 'junit:junit:4.11'!
}!
😎
SCENARIOS
ü Executable/Launchable application
ü Executable fat jar
ü Installable application
EXECUTABLELAUNCHABLE APPLICATION
<project ...>!
<build>!
<plugins>!
<plugin>!
<groupId>org.codehaus.mojo</groupId>!
<artifactId>exec-maven-plugin</artifactId>!
<version>1.2.1</version>!
<configuration>!
<mainClass>sample.Foo</mainClass>!
</configuration>!
</plugin>!
</plugins>!
</build>!
</project>!
$ mvn compile exec:java
😐
apply plugin: 'java'!
apply plugin: 'application'!
!
mainClassName = 'sample.Foo'!
$ gradle run
😎
EXECUTABLE FAT JAR
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>sample.Foo</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</plugin>
<plugins>
$ mvn package –DskipTests=true
😐
plugins {!
id 'com.github.johnrengelman.shadow' version '1.1.2'!
}!
!
apply plugin: 'java'!
apply plugin: 'application'!
!
mainClassName = 'sample.Foo'!
!
repositories { jcenter() }!
!
dependencies { compile 'commons-lang:commons-lang:2.6' }!
$ gradle shadowJar
😎
Installable application .!
├── bin!
│ ├── sample!
│ └── sample.bat!
└── lib!
├── commons-lang-2.6.jar!
└── sample-0.0.0-SNAPSHOT.jar!
1. Add assembly plugin!
2. Create assembly descriptor!
1. Dist option for building the directory structure!2. Zip option for packing all in a single file!
3. Create launch scripts (for all target platforms!)!
4. Might require custom profiles!
OR configure the appassembler plugin!
😐
apply plugin: 'java'!
apply plugin: 'application’!
mainClassName = 'sample.Foo'!
!
repositories {!
jcenter()!
}!
!
dependencies {!
compile 'commons-lang:commons-lang:2.6'!
}!
$ gradle distZip
😎
BUT WAIT, THERE’S
MORE
$ gvm install lazybones $ lazybones create gradle-quickstart sample
license versions stats bintray shadow izpack java2html git coveralls
asciidoctor jbake markdown livereload gretty Nexus watch wuff spawn
THANK YOU!
HTTP://PEOPLE.CANOO.COM/SHARE
Andres Almiray Ix-chel Ruiz
@aalmiray @ixchelruiz
Recommended