How to compile JasperReports (.jrxml) files during build process?


(Oliver Siegmar) #1

I’m trying to migration from Maven to Gradle. In Maven I’m using the jasperreports-maven-plugin from org.codehaus.mojo to compile .jrxml (JasperReports) files during the build process. How can this be done with Gradle? The JasperReports files are in src/main/jasperreports/*.jrxml and should be compiled to build/classes/jasperreports.


(Benjamin Muschko) #2

In Gradle you cannot use a Maven plugin. I am not aware of a Gradle plugin that helps you with this. There seems to be an Ant task for compiling Jasper report files which you can integrate into your build. Check out this posting which tries to achieve the same task.


(Oliver Siegmar) #3

Thanks for your reply!

I checked this out, but it doesn’t work. First I had to rename configuration to configurations. Now I get this:

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "srcDir" on "source set 'jasper'", value: "/projectpath...".
:myModule:compileJasperJava FAILED
  FAILURE: Build failed with an exception.
  * Where:
Build file '/projectpath/build.gradle' line: 133
  * What went wrong:
Execution failed for task ':myModule:compileJasperJava'.
> Could not find property 'classesDir' on source set 'jasper'.

I googled around but couldn’t find a working solution. Also I’m very new to Gradle and don’t know how to solve problems like that. Any clues?


(uklance) #4

srcDir is a convenience method, not a property. The property is srcDirs. I think you’ll need to do something like:

sourceSets {
     jasper {
         srcDir file(relativePath('src/main/templates'))
        output.classesDir = file(relativePath('target/jasper'))
    }
 }
   task compileJasperJava(overwrite: true) << {
     ant {
         taskdef(name: 'jrc', classname: 'net.sf.jasperreports.ant.JRAntCompileTask', classpath: configurations.jasperreports.asPath)
         sourceSets.jasper.output.classesDir.mkdirs()
         jrc(srcdir: sourceSets.jasper.srcDirs[0], destdir: sourceSets.jasper.output.classesDir) {
             include(name:'**/*.jrxml')
         }
     }
 }

(Peter Niederwieser) #5

As of Gradle 1.0+, this isn’t valid source set syntax. Probably better to just use ‘def jasperSourceDir = …’ and ‘def jasperTargetDir = …’. Also, ‘relativePath()’ and ‘(overwrite: true)’ can be omitted.


(Oliver Siegmar) #6

Thank’s a lot! This is the configuration that works for my case:

configurations {
    jasperreports {
        transitive = true
    }
}
  dependencies {
    jasperreports 'net.sf.jasperreports:jasperreports:5.0.1'
}
  task compileJasperJava(dependsOn: 'compileJava') << {
    def jasperSourceDir = file('src/main/jasperreports')
    def jasperTargetDir = file('build/classes/main/jasperreports')
    ant {
        taskdef(name: 'jrc', classname: 'net.sf.jasperreports.ant.JRAntCompileTask', classpath: configurations.jasperreports.asPath)
        jasperTargetDir.mkdirs()
        jrc(srcdir: jasperSourceDir, destdir: jasperTargetDir) {
            classpath(path: sourceSets.main.output.classesDir)
            include(name: '**/*.jrxml')
        }
    }
}
  classes.dependsOn compileJasperJava

(rani sinha) #7

Please help me http://forums.gradle.org/gradle/topics/unable_to_compile_jasper_using_gradle with this


(rani sinha) #8

Please help me http://forums.gradle.org/gradle/topics/unable_to_compile_jasper_using_gradle with this


(rani sinha) #9

Please help me http://forums.gradle.org/gradle/topics/unable_to_compile_jasper_using_gradle with this