Loading

Quipoin Menu

Learn • Practice • Grow

jenkins / Building Java Apps
tutorial

Building Java Apps

Java applications often use build tools like Maven or Gradle. Jenkins can integrate with these tools to compile, test, and package your code.

Installing Maven/Gradle Plugins

Install the "Maven Integration" plugin (for Maven) or "Gradle" plugin. Then configure JDK and Maven/Gradle installations under "Manage Jenkins" → "Global Tool Configuration".

Building a Maven Project (Freestyle)

Create a freestyle job, set SCM to Git, then add a build step "Invoke top‑level Maven targets". Enter goals: clean compile test or package.

Maven in Declarative Pipeline

Use the sh step to run Maven, or the withMaven wrapper.
pipeline {
agent any
tools {
maven 'Maven-3.9'
jdk 'JDK-17'
}
stages {
stage('Build') {
steps {
sh 'mvn clean compile'
}
}
stage('Test') {
steps {
sh 'mvn test'
}
}
stage('Package') {
steps {
sh 'mvn package'
archiveArtifacts artifacts: 'target/*.jar'
}
}
}
}

Using Gradle

Similarly, you can use the Gradle wrapper (gradlew) in your repository.
stage('Build') {
steps {
sh './gradlew build'
}
}

Publishing Test Reports

Jenkins can parse JUnit‑style XML test reports. After running tests, use the junit step.
post {
always {
junit 'target/surefire-reports/*.xml'
}
}


Two Minute Drill
  • Configure JDK and Maven/Gradle in Global Tool Configuration.
  • Use tools directive to select specific versions.
  • Archive artifacts with archiveArtifacts.
  • Publish JUnit test reports with junit.

Need more clarification?

Drop us an email at career@quipoinfotech.com