Reader small image

You're reading from  Gradle Effective Implementations Guide - Second Edition

Product typeBook
Published inMay 2016
Reading LevelIntermediate
Publisher
ISBN-139781784394974
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Hubert Klein Ikkink
Hubert Klein Ikkink
author image
Hubert Klein Ikkink

Hubert Klein Ikkink was born in 1973 and lives in Tilburg, the Netherlands, with his beautiful wife and gorgeous children. He is also known as mrhaki, which is simply the initials of his name prepended by mr. He studied Information Systems and Management at the Tilburg University. After finishing his studies he started to work at a company which specialized in knowledge-based software. There he started writing his first Java software (yes, an applet!) in 1996. Over the years his focus switched from applets, to servlets, to Java Enterprise Edition applications, to Spring-based software. In 2008 he wanted to have fun again when writing software. The larger projects he was working on were more about writing configuration XML files, tuning performance and less about real development in his eyes. So he started to look around and noticed Groovy as a good language to learn about. He could still use existing Java code, libraries, and his Groovy classes in Java. The learning curve isn’t steep and to support his learning phase he wrote down interesting Groovy facts in his blog with the title Groovy Goodness. He posts small articles with a lot of code samples to understand how to use Groovy. Since November 2011 he is also a DZone Most Valuable Blogger (MVB); DZone also posts his blog items on their site. In 2010, 2011, and 2012 Hubert was invited to speak at Gr8Conf in Copenhagen, Denmark. This is a very good conference with all the project leaders of Groovy and Groovy-related projects. In November 2010 he presented a Gradle talk at the J-Fall conference of the Dutch Java User Group. In November 2011 he presented about the new features in Groovy 1.8 at the same conference. The conference is visited by 1000 Java developers and he got the chance to educate some of them about the greatness of Gradle and Groovy. Hubert works for a company called JDriven in the Netherlands. JDriven focuses on technologies that simplify and improve development of enterprise applications. Employees of JDriven have years of experience with Java and related technologies and are all eager to learn about new technologies. Hubert works on projects using Grails and Java combined with Groovy and Gradle.
Read more about Hubert Klein Ikkink

Right arrow

Chapter 11. Gradle in the Enterprise

It is good practice to have a continuous integration tool in a software project. With a continuous integration tool, we can automatically build our software in a controlled environment. In this chapter, we are going to take a look at the support for Gradle in several continuous integration tools.

First, we are going to create a sample Java project and use Git as a version control repository. Then, we are going to see how continuous integration servers, such as Jenkins, JetBrains TeamCity, and Atlassian Bamboo, support Gradle.

We will cover the following topics in this chapter:

  • Creating a sample Java project

  • Using Gradle with Jenkins

  • Running Gradle tasks with JetBrains TeamCity

  • Learning how to set up Atlassian Bamboo for Gradle

Creating a sample project


Before we can see the support for Gradle in the several continuous integration servers, we need to have a sample project. We are going to create a very simple Java project with a test class and add it to a Git repository in this section.

We have already created a Java project earlier. We are going to reuse the code in this chapter for our sample project. We want a test in our project so that we can see how the continuous integration tools can handle test results. Finally, we want more than one artifact for our project; we also want a JAR file with the compiled classes, source code, and Javadoc-generated documentation.

  1. We will first create a build.gradle file in a directory with the following contents:

            // We create a Java project so we need the Java plugin 
            apply plugin: 'java' 
     
            // Set base name for archives. 
            archivesBaseName = 'gradle-sample' 
     
            // Version of the project. 
            version...

Using Jenkins


One of the most popular open source continuous integration tools is Jenkins. The good news is that Jenkins has support for Gradle via the Gradle plugin. Let's see how to use the plugin to add our little Java project to Jenkins.

To install Jenkins on our computer, we must first download the installation files from the Jenkins website. A native installer is available for Mac OS X, Windows, and Linux. We can simply run the installer software to install Jenkins on our computer. We can also download a WAR file and deploy it to a Java web container to install Jenkins. The WAR file is also a Java executable archive. This means that we can simply run the WAR file with the java -jar command to execute Jenkins.

Adding the Gradle plugin

  1. First, we must install the Gradle plugin in Jenkins.

  2. We will launch a web browser and access http://localhost:8080 . From the Jenkins main page, we will select the Manage Jenkins link, which takes us to the appropriate page, as shown in the following image...

Using JetBrains TeamCity


JetBrains TeamCity is a commercial continuous integration server. TeamCity has a Professional Server license. This means that we can create 20 build configurations and one build agent. If we need more configurations or build agents, we can purchase other licenses. In this section, we will see how to create a build plan with Gradle.

We can download installer software for Mac OS X, Windows, and Linux from the JetBrains TeamCity website. We run the installer software to install TeamCity on our computer. TeamCity is also available as an archive for all platforms. To install the archive, we only have to unpack the contents to a directory on our computer. TeamCity is also available as a WAR file, which can be deployed to a Java web container.

Creating a project

In TeamCity we must create a project with the build configuration we want to be executed. Let's see how we can add a project:

  1. After we install TeamCity, we will open a web browser and go to  http://localhost:8111/ ...

Using Atlassian Bamboo


The last continuous integration tool that we are going to configure is Atlassian Bamboo. Bamboo is a commercial continuous integration server. There is a 30-day evaluation license available from the Atlassian website. We will discuss how to configure Bamboo to use Gradle as a build tool for our Java project.

We can install Bamboo on our local computer. We will first need to download the installation package from the Bamboo website. We can choose native installers for Mac OS X, Windows, and Linux. Alternatively, we can simply download a packaged version and unzip it in a directory on our computer. Finally, we can download a WAR file and deploy it to a web container.

Defining a plan

Bamboo has no Gradle runner or plugin, but we can define a build plan and add the so-called script task. A script task can run any script as part of the build plan. To make sure that Bamboo can build our Java project, we must add the Gradle Wrapper scripts to the project.

We will run the wrapper...

Summary


In this chapter, we have discussed how we should configure continuous integration tools, such as Jenkins, JetBrains TeamCity, and Atlassian Bamboo, to build our Java project with Gradle.

Jenkins and TeamCity have good support for Gradle builds. We can choose to use either a locally-installed Gradle version or the Gradle task wrapper scripts. Defining which tasks to run is easy.

Bamboo has no real support for Gradle builds. We can use the script build option and Gradle task wrapper support to work around this. This way, we can still run Gradle builds with Bamboo.

In the next chapter, we will discuss how to integrate Gradle with Integrated Development Environments (IDEs) such as Eclipse and JetBrains IntelliJ IDEA.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Gradle Effective Implementations Guide - Second Edition
Published in: May 2016Publisher: ISBN-13: 9781784394974
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Hubert Klein Ikkink

Hubert Klein Ikkink was born in 1973 and lives in Tilburg, the Netherlands, with his beautiful wife and gorgeous children. He is also known as mrhaki, which is simply the initials of his name prepended by mr. He studied Information Systems and Management at the Tilburg University. After finishing his studies he started to work at a company which specialized in knowledge-based software. There he started writing his first Java software (yes, an applet!) in 1996. Over the years his focus switched from applets, to servlets, to Java Enterprise Edition applications, to Spring-based software. In 2008 he wanted to have fun again when writing software. The larger projects he was working on were more about writing configuration XML files, tuning performance and less about real development in his eyes. So he started to look around and noticed Groovy as a good language to learn about. He could still use existing Java code, libraries, and his Groovy classes in Java. The learning curve isn’t steep and to support his learning phase he wrote down interesting Groovy facts in his blog with the title Groovy Goodness. He posts small articles with a lot of code samples to understand how to use Groovy. Since November 2011 he is also a DZone Most Valuable Blogger (MVB); DZone also posts his blog items on their site. In 2010, 2011, and 2012 Hubert was invited to speak at Gr8Conf in Copenhagen, Denmark. This is a very good conference with all the project leaders of Groovy and Groovy-related projects. In November 2010 he presented a Gradle talk at the J-Fall conference of the Dutch Java User Group. In November 2011 he presented about the new features in Groovy 1.8 at the same conference. The conference is visited by 1000 Java developers and he got the chance to educate some of them about the greatness of Gradle and Groovy. Hubert works for a company called JDriven in the Netherlands. JDriven focuses on technologies that simplify and improve development of enterprise applications. Employees of JDriven have years of experience with Java and related technologies and are all eager to learn about new technologies. Hubert works on projects using Grails and Java combined with Groovy and Gradle.
Read more about Hubert Klein Ikkink