DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • How To Add Three Photo Filters to Your Applications in Java
  • Providing Enum Consistency Between Application and Data
  • How To Convert HTML to PNG in Java
  • Setting Up Your Java Pipeline With Azure DevOps and Docker

Trending

  • The Scrum Guide Expansion Pack
  • Maximizing Productivity: GitHub Copilot With Custom Instructions in VS Code
  • A Complete Guide to Modern AI Developer Tools
  • Vibe Coding: Conversational Software Development — Part 1 Introduction
  1. DZone
  2. Coding
  3. Java
  4. Concourse Caching for Java Maven and Gradle Builds

Concourse Caching for Java Maven and Gradle Builds

Check out how Concourse CI now allows you to cache paths between task runs, opening the door to much faster Maven and Gradle builds.

By 
Biju Kunjummen user avatar
Biju Kunjummen
·
Aug. 17, 17 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
16.3K Views

Join the DZone community and get the full member experience.

Join For Free

Concourse CI 3.3.x has introduced the ability to cache paths between task runs. This feature helps speed up tasks which cache content in specific folders — here I will demonstrate how this feature can be used for speeding up Maven- and Gradle-based Java builds.

The code and the pipeline that I am using for this post is available at my GitHub repo here.

Let me start with the Gradle build. If I were to build the project using a Gradle wrapper using the following command...

./gradlew clean build


...then Gradle would download the dependent libraries into a ".gradle" folder in the users home folder by default. This location of this folder can be changed using a "GRADLE_USER_HOME" environment variable, which is what I will be using in a Concourse task to control the location of a cached path.

A Concourse task that builds my project looks like this:

---
platform: linux
image_resource:
  type: docker-image
  source:
    repository: openjdk
    tag: 8-jdk
inputs:
  - name: repo
outputs:
  - name: out
run:
  path: /bin/bash
  args:
    - repo/ci/tasks/build.sh
 
caches:
  - path: .gradle/
  - path: .m2/
 
params:
  PROJECT_TYPE: 


See that the cache's parameter is specified as ".gradle" above. So all I have to do now is to ensure that Gradle uses this location as its home folder, which I would do in my build script:

export ROOT_FOLDER=$( pwd )
export GRADLE_USER_HOME="${ROOT_FOLDER}/.gradle"


The process to cache Maven resources for a Maven build is along the same lines. Maven caches the dependent JARs in a location that can be specified in a variety of ways. The one I have used is to specify this location via a dynamically generated settings.xml file the following way:

M2_HOME=${HOME}/.m2
mkdir -p ${M2_HOME}
 
M2_LOCAL_REPO="${ROOT_FOLDER}/.m2"
 
mkdir -p "${M2_LOCAL_REPO}/repository"
 
cat > ${M2_HOME}/settings.xml <<EOF
 
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                          https://maven.apache.org/xsd/settings-1.0.0.xsd">
      <localRepository>${M2_LOCAL_REPO}/repository</localRepository>
</settings>
 
EOF


That is quite a bit of bash scripting, but all it is doing is generating a settings.xml with a localRepository tag set to the ".m2/repository" folder, which is relative to the temporary folder created by Concourse for the build — and thus can be cached.

With these changes in place, the behavior is that the downloads happen for the first run of the task. but then get cached for subsequent runs. In my local Concourse set-up, a Gradle build takes about 2 mins for a first-time build, then takes about 20 seconds for a subsequent build!

You can try out this feature in my demo project here.

Continuous Integration/Deployment Cache (computing) Gradle Apache Maven Java (programming language)

Published at DZone with permission of Biju Kunjummen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Add Three Photo Filters to Your Applications in Java
  • Providing Enum Consistency Between Application and Data
  • How To Convert HTML to PNG in Java
  • Setting Up Your Java Pipeline With Azure DevOps and Docker

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: