iconuk 2015 - gradle up!

Post on 21-Jan-2018

697 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

Gradle Up!

René Winkelmeyer midpoints GmbH

2

René Winkelmeyer Head of Development

midpoints GmbH http://www.midpoints.de IBM Advanced Business Partner IBM Design Partner (Notes Domino, Mobile, Verse) Apple Enterprise Developer und MDM Group Member Samsung Enterprise Alliance Partner Services - Enterprise Mobility Service - Mobile Device und Application Management - IBM Traveler und IBM Mobile Connect

About me

3

•  Skype

muenzpraeger •  Twitter

muenzpraeger •  LinkedIn

muenzpraeger •  Slideshare

muenzpraeger

•  Web https://blog.winkelmeyer.com http://www.midpoints.de

•  Mail mail@winkelmeyer.com rene.winkelmeyer@midpoints.de

OpenNTF •  File Navigator •  Generic NSF View Widget for IBM Connections

About me

René Winkelmeyer Head of Development

4

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

5

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

6

Why this session?

Doing things for a first time?

Doing things for a second time?

Doing things more often?

Noteworthy: http://www.slideshare.net/HollyCummins/confessions-of-an-automation-addict

Shoot and forget!

Write down the needed steps.

Automate!

7

Tasks excerpt in software development and delivery

Compile binary code Set version number

Execute integration tests

Generate JavaDoc

Resolve/update dependencies

Modify MANIFEST.MF

Deploy to QA system Generate production package Compile binary code

Automated code validation

Set binary file name

...

Debugging

Continous Integration

Deploy to different platforms Generate installers

Execute regression tests

Include documentation

Apply translations ...

... ...

...

...

8

Tasks excerpt in software development and delivery

Compile binary code Set version number

Execute integration tests

Generate JavaDoc

Resolve/update dependencies

Modify MANIFEST.MF

Deploy to QA system Generate production package Compile binary code

Automated code validation

Set binary file name

...

Debugging

Continous Integration

Deploy to different platforms Generate installers

Execute regression tests

Include documentation

Apply translations ...

... ...

...

...

9

Example A – Resolve/update dependencies

§  You want to use a specific 3rd party library, i. e. for supporting MIME SMTP Mailing (mail-1.3.4.jar)

Search, compile

and copy hell

mail-1.3.4

slf4j-3.1.1

commons-io-4.2.1

guava-17.1

log4j-2.3.4

10

Example A – Resolve/update dependencies

§  The 3rd party library needs to be updated from mail-1.3.4.jar to mail-1.4.1.jar

Search, compile,

delete and copy hell

mail-1.4.1

slf4j-4.2.1 log4j-2.5.1

commons-io-4.4.5

guava-17.1

commons-codec-2.1.3

11

Example B – Automated code validation

§  Code validation can be done using 3rd party libraries/tools

§  FindBugs

§  CheckStyle

§  PMD

§  ...

Who executes them

– and when?

Where are they

executed? IDE?

Where are they

documented?

12

Example C: Set version number

§  Define the version number so that it can be re-used

§  In the UI of your web application

§  In the file name of the compiled code

§  In the attached product documentation/help

§  In JavaDoc

§  ... Where do you set it

nowadays?

13

Example D: Generate production package

§  Generate a production ready package with the same servlet based application (optionally including server configuration) for

§  Domino HTTP

§  WebSphere Liberty

§  TomEE

§  ...

Who maintains the

needed steps?

14

Build automation – some PROs

§  Frees YOU from the hassle of repeating tasks

§  Makes SURE that you can concentrate on the essential part – coding

§  Helps to enforce STANDARDS across multiple developers and/or projects

§  Eases the MAINTAINABILITY of your applications

§  And much more!

15

Automated Builds (here: Atlassian Bamboo)

16

Build automation – It’s not for free!

§  Takes some time for adoption!

§  You‘ve to give up some (bad) habits.

§  Infrastructure needed (i. e. for automated testings).

17

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

18

Why Gradle - and not Maven or Ant?

§  Please not the same discussion as with Windows vs. Linux

§  All widely accepted

§  Personal preferences may apply (like XML vs. custom DSL)

§  Make your choice!

19

Why Gradle - and not Maven or Ant?

Source: http://zeroturnaround.com/rebellabs/java-build-tools-part-2-a-decision-makers-comparison-of-maven-gradle-and-ant-ivy/

20

Why Gradle - and not Maven or Ant?

convention-over-configuration

vs.

configuration-over-convention

21

Example configuration (Maven vs. Gradle)

§  Comparing a simple build configuration for code testing purposes

§  Use JUnit and Hamcrest

§  Apply CheckStyle, FindBugs and PMD

Source: http://technologyconversations.com/2014/06/18/build-tools/ Code: https://github.com/vfarcic/JavaBuildTools

22

Maven configuration (pom.xml)

23

Gradle configuration (build.gradle)

24

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

25

Basics – General

§  Gradle is built on top of Groovy – you „configure“ in code!

§  You don‘t have to learn Groovy in the first place when using Gradle.

§  https://en.wikipedia.org/wiki/Groovy_(programming_language)

§  Build scripts are using a custom DSL (Domain Specific Language)

§  https://docs.gradle.org/current/dsl/index.html

26

Basics – DSL

27

Basics – Releases and availability

§  New versions are delivered every 4-6 weeks

§  Current version is 2.7 (14.09.2015)

§  Release Notes: https://docs.gradle.org/2.7/release-notes

§  Download: https://gradle.org/gradle-download/

28

Components

gradle

gradlew

Gradle daemon

build.gradle

settings.gradle

gradle.properties

Binaries Configuration

29

Binaries

§  You can use either way the gradle executable of the binary package or the gradle wrapper (gradlew).

§  The wrapper allows you to use Gradle on systems that don‘t have Gradle installed (yet)

§  Enhance your build times by using the daemon

§  https://docs.gradle.org/2.7/userguide/gradle_daemon.html

30

Configuration – Global

§  Custom global properties can be set via a gradle.properties file

§  Project build dir

§  Users gradle home dir (i. e. ~/.gradle/ on *nix systems)

§  Via System properties

§  Define proxy settings, passwords for remote repository access and much more

§  https://docs.gradle.org/current/userguide/build_environment.html

31

Configuration – Project specific

§  Gradle uses two build script files

§  build.gradle

§  settings.gradle

§  Minimum in the root of the project folder structure

§  Can have more of them in a multi-project structure

32

Tasks

§  Gradle offers you a variety of built-in tasks.

§  Tasks can either run standalone – or they depend on the successful execution of other tasks and run in a chain.

§  Configuration provided in the build.gradle file or via (custom) plugins.

§  You can write custom tasks directly in the build.gradle file.

33

Task example – gradle init

§  Creates a new Gradle project according to the specified type (or a basic Gradle project if no type is supplied)

Dedicated tasks

Different types for init are available

34

Task example – gradle tasks

§  Lists all tasks that are available to the current project

Name and description

35

Tasks – gradle test

§  Runs the test cases of the project (if you test your code ;-))

Gradle stores hash values of task in- and output and skips the processing if no changes haven been made.

36

IDE integration (here: Eclipse)

I recommend this at the moment

Relatively new, needs improvement

37

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

38

Your first Gradle project – start small

§  We‘ll create a simple Java project here

§  Init a standalone project (non-Eclipse specific)

§  Learn about the project structure §  Generate a runnable JAR file

§  Run the JAR file

39

Init the project

40

Learn about the project structure

build script

build script

Gradle wrapper files

Example source code

41

Starting point for a build.gradle configuration

Standard and custom

plugins are available

jcenter references to Bintray, you can also use i. e. mavenCentral,

mavenLocal and local directoreis

Define the needed dependencies that are needed by this project.

42

Assemble the JAR file

Gradle detects unavailable dependencies and downloads them

automatically.

43

Standard project structure

The build directory contains the output of the Gradle build

44

Run the assembled JAR file (or try to ;-))

The build/libs directory normally contains the generated packages.

45

Add your first additional plugin

Adding the „application“ plugin for getting a runnable JAR file

New property that tells the „application“ plugin the name of the main class.

46

Validate the new tasks (added by the plugin)

New tasks

47

Run the JAR file

Output of the sample code

48

Create a distribution package for the JAR file

Task of the „application“ plugin

49

Validate the distribution package

installDist generates the fully runnable distribution package

50

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

51

Building a web application

§  We‘ll create a simple web application (with a single servlet) which will be used from within the Eclipse IDE

§  Populate a blank build.gradle file with the needed settings

§  Use Maven Central as remote repository §  Generate a WAR file

§  Run the WAR in a Jetty container

52

Populate new build.gradle file

Code generation should respect Java 8

Plugins that help with Eclipse integration

Adds tasks for WAR files

53

Initialize Eclipse project

Preparing the Gradle project for Eclipse

54

Validate Eclipse data creation

55

Import as “Gradle Project” 1/2

56

Import as “Gradle Project” 2/2

57

Create new Source Folders 1/2

58

Create new Source Folders 1/2

59

Create a simple servlet (or try to ;-))

HttpServlet isn‘t available

60

Repository and dependency configuration

Adding mavenCentral as new remote repo

Adding the servlet classes as new dep

61

Refresh dependencies to download them (if needed)

62

“Finish” the simple servlet

63

Add web.xml configuration 1/3

64

Add web.xml configuration 2/3

65

Add web.xml configuration 3/3

66

Need to run the WAR? Here we go!

Another plugin that allows quick tests within a Jetty container

67

Quick start from within Eclipse

Use the Quick Launcher to run the WAR in the Jetty container

68

Using WebSphere Liberty? Lets ci.gradle help you!

https://github.com/WASdev/ci.gradle

69

Agenda

§  Build Automation – Why?

§  Why Gradle - and not Maven or Ant?

§  Theory First - Gradle Basics

§  Your first Gradle project – start small

§  Building a web application

§  Building an OSGi plug-in project

70

Building an OSGi plugin

§  Standard OSGi support in Gradle isn‘t very good

§  A simple plugin to help with OSGi-Manifest generation

§  https://docs.gradle.org/current/userguide/osgi_plugin.html

And now what?

71

Wuff – to the rescue?

https://github.com/akhikhl/wuff

72

Wuff – the solution?

§  Great for all Eclipse related build tasks.

§  Missing features – DIY

§  Feature generation

§  Updatesite creation

73

Wuff – additional considerations (for Domino)

74

Wuff – find the custom build here

§  https://github.com/petarov/wuff

Thanks to Petar, he did some of the dirty work

75

Thank you!

top related