Operations 7 min read

Integrating Maven, Ant, Gradle, and NPM with Jenkins: Prerequisites, Installation, and Common Commands

This guide explains how to set up Maven, Ant, Gradle, and NPM in Jenkins, covering system prerequisites, installation steps, Jenkins configuration, and frequently used build commands for each tool.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Integrating Maven, Ant, Gradle, and NPM with Jenkins: Prerequisites, Installation, and Common Commands

1. Integrate Maven

1.1 Prerequisites

JDK: Maven 3.3+ requires JDK 1.7+; no minimum memory requirement.

Disk: at least 1 GB free space; OS: no restrictions.

Download Maven from the official site.

1.2 Install Maven

tar zxf apache-maven-3.6.0-bin.tar.gz -C /usr/local/
# Set global variables (/etc/profile)
export MAVEN_HOME=/usr/local/apache-maven-3.6.0
export PATH=$PATH:$MAVEN_HOME/bin
source /etc/profile

1.3 Jenkins configuration for Maven

System Settings → Global Tool Configuration

Create a Jenkinsfile

node {
    stage ("build"){
        mavenHome = tool 'M3'
        sh "${mavenHome}/bin/mvn -v"
    }
}

Build test Maven integration with Jenkins is now complete.

1.4 Common Maven commands

clean install -DskipTests
clean package

2. Integrate Ant

2.1 Prerequisites

Download Ant from the official site.

Download

2.2 Install Ant

tar zxf apache-ant-1.10.5-bin.tar.gz -C /usr/local/
# Add global variables (/etc/profile)
export ANT_HOME=/usr/local/apache-ant-1.10.5
export PATH=$PATH:$MAVEN_HOME/bin:$ANT_HOME/bin
source /etc/profile

Test

2.3 Jenkins configuration for Ant

System Settings → Global Tool Configuration

Create a Jenkinsfile

node {
    stage ("build"){
        antHome = tool 'ANT'
        sh "${antHome}/bin/ant -version"
    }
}

Build test Ant integration with Jenkins is now complete.

2.4 Common Ant command

ant -buildfile -f build.xml

3. Integrate Gradle

3.1 Prerequisites

Download Gradle from the official site.

Download

3.2 Install Gradle

unzip gradle-5.3-bin.zip -d /usr/local/
# Add global variables (/etc/profile)
export GRADLE_HOME=/usr/local/gradle-5.3
export PATH=$PATH: $GRADLE_HOME/bin
source /etc/profile

3.3 Jenkins configuration for Gradle

System Settings → Global Tool Configuration

Create a Jenkinsfile

node {
    stage ("gradlebuild"){
        gradleHome = tool 'GRADLE'
        sh "${gradleHome}/bin/gradle -v"
    }
}

Build test Gradle integration with Jenkins is now complete.

3.4 Common Gradle commands

./gradlew -v – displays version; first run downloads Gradle if not present.

./gradlew clean – deletes the build folder under HelloWorld/app .

./gradlew build – checks dependencies and compiles the package.

./gradlew assembleDebug – builds a debug APK.

./gradlew assembleRelease – builds a release APK.

./gradlew installRelease – packages and installs the release build.

./gradlew uninstallRelease – uninstalls the release package.

4. Integrate NPM

4.1 Prerequisites

Download Node.js from the official site.

4.2 Install Node

tar xf node-v10.15.3-linux-x64.tar.xz -C /usr/local/
# Add global variables (/etc/profile)
export NODE_HOME=/usr/local/node-v10.15.3-linux-x64
export PATH=$PATH: $NODE_HOME/bin
source /etc/profile

Test the installation.

4.3 Jenkins configuration for NPM

Node is not listed in Jenkins global tool configuration; define it directly in the Jenkinsfile.

Jenkinsfile example:

node {
    stage ("npmbuild"){
        sh """
           export npmHome=/usr/local/node-v10.15.3-linux-x64
           export PATH=$PATH:$npmHome/bin
           npm -v
           """
    }
}

Build test.

4.4 Common NPM build command

npm install && npm run build

Read the original article for more details.

CI/CDGradleMavenbuild-toolsnpmJenkinsAnt
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.