JasperReport with Gradle
Introduction
I recently migrated my project from Maven to Gradle. In the process I faced lots of challenges, one of them is compiling JasperReport.
This post explains how to compile jasperreport’s jrxml
to jasper
and package jasper
to the jar.
Prerequisites
- JDK 1.7 or later
- Gradle 2
Project Structure
It’s a typical gradle structure except src/main/jasperreports
which will have the *.jrxml
files.
Project Root
|--build.gradle
|--settings.gradle
|--src/
|--main/
|--jasperreports/
|--java/
Gradle Script
apply plugin: 'java'
repositories {
mavenCentral()
jcenter()
maven{url "http://jasperreports.sourceforge.net/maven2/"}
maven{url "http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/"}
}
configurations {
jasperreports {
transitive = true
}
}
gradle.projectsEvaluated {
processResources.dependsOn(compileJasperReports)
}
dependencies {
jasperreports 'net.sf.jasperreports:jasperreports:5.6.0',
'org.codehaus.groovy:groovy-all:2.3.6'
}
task compileJasperReports {
def jasperSourceDir = file('src/main/jasperreports')
ant {
taskdef(name: 'jrc', classname: 'net.sf.jasperreports.ant.JRAntCompileTask', classpath: configurations.jasperreports.asPath)
sourceSets.main.output.classesDir.mkdirs()
jrc(srcdir: jasperSourceDir, destdir: sourceSets.main.output.classesDir) {
classpath(path: sourceSets.main.output.classesDir)
include(name: '**/*.jrxml')
}
}
}
This build script has two maven urls which has the dependency for jasperreport which are not available in maven central repo.
Conclusion
When the project is build the *.jrxml
files will be compiled to *.jasper
filed and copied to the classes folder.
So when the project is packaged these *.jrxml
files will be available in classpath.
Code
The sample project is available in Github
Newest Posts
- Anaconda Proxy Repository in Nexus OSS 3
- Node Command Line Interface Tool in TypeScript.
- Continuous Deployment for Jekyll using Bitbucket Pipeline to deploy in Github
- Grunt Watch and Livereload (Using BrowserSync) in Jekyll
- Java Thick Client with Kerberos for RESTful Service
- Install Gradle in Cloud9 IDE
- Localhost Authentication for Spring Kerberos
- JasperReport with Gradle
- Jasper Reports Font Extension
- JDK Folder from Installation EXE