Giter Site home page Giter Site logo

gmazelier / gradle-jasperreports Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 20.0 192 KB

Provides the capability to compile JasperReports design files.

Home Page: https://plugins.gradle.org/plugin/com.github.gmazelier.jasperreports

License: Apache License 2.0

Groovy 100.00%
jasperreports-plugin groovy

gradle-jasperreports's Introduction

Gradle JasperReports Plugin

Build Status Gradle Plugin Portal

Description

Provides the capability to compile JasperReports design files. This plugin is designed to work like the Maven plugins Maven 2 JasperReports Plugin and JasperReports-plugin. Much of this was inspired by these two projects.

Usage

This plugin provides one main task, compileAllReports. It uses incremental task feature to process out-of-date files and parallel collections from GPars for parallel processing. Adapt your build process to your own needs by defining the proper tasks depedencies (see Custom Build Process below).

If your designs compilation needs to run after Groovy compilation, running compileAllReports should give a similar output:

$ gradle compileAllReports
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:prepareReportsCompilation
:compileAllReports
21 designs compiled in 2222 ms

BUILD SUCCESSFUL

Total time: 6.577 secs

To clean up and start fresh, simply run:

$ gradle clean compileAllReports

Installation

Using the pluging DSL...

plugins {
  id "com.github.gmazelier.jasperreports" version "0.4"
}

Using the legacy plugin application...

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.github.gmazelier:jasperreports-gradle-plugin:0.4"
  }
}

apply plugin: "com.github.gmazelier.jasperreports"

Configuration

Below are the parameters that can be used to configure the build:

Parameter Type Description
srcDir File Design source files directory. Default value: src/main/jasperreports
tmpDir File Temporary files (.java) directory. Default value: ${project.buildDir}/jasperreports
outDir File Compiled reports file directory. Default value: ${project.buildDir}/classes/main
srcExt String Design source files extension. Default value: '.jrxml'
outExt String Compiled reports files extension. Default value: '.jasper'
compiler String The report compiler to use. Default value: net.sf.jasperreports.engine.design.JRJdtCompiler
keepJava boolean Keep temporary files after compiling. Default value: false
validateXml boolean Validate source files before compiling. Default value: true
verbose boolean Verbose plugin outpout. Default value: false
useRelativeOutDir boolean The outDir is relative to java classpath. Default value: false
classpath Iterable<File> Extra elements to add to the classpath when compile. Default value: []

Example

Below is a complete example, with default values:

jasperreports {
    srcDir = file('src/main/jasperreports')
    tmpDir = file('${project.buildDir}/jasperreports')
    outDir = file('${project.buildDir}/classes/main')
    srcExt = '.jrxml'
    outExt = '.jasper'
    compiler = 'net.sf.jasperreports.engine.design.JRJdtCompiler'
    keepJava = false
    validateXml = true
    verbose = false
    useRelativeOutDir = false
    classpath = []
}

Custom Build Process

Adding a task dependency is very simple. For example, if you want to make sure that Groovy (and Java) compilation is successfully performed before JasperReports designs compilation, just add the following to your build script:

compileAllReports.dependsOn compileGroovy

Custom Classpath

Sharing dependencies

Here's a way to share dependencies (joda-time in this example) between the main project and the designs compilation:

buildscript {
  ext {
    libs = [
      jrdeps: [
        // all dependencies shared with JasperReports
        'joda-time:joda-time:2.7'
      ]
    ]
  }
  repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'http://jaspersoft.artifactoryonline.com/jaspersoft/third-party-ce-artifacts/'
    }
    maven {
      url 'http://jasperreports.sourceforge.net/maven2'
    }
    maven {
      url 'http://repository.jboss.org/maven2/'
    }
  }
  dependencies {
    classpath 'com.github.gmazelier:jasperreports-gradle-plugin:0.3.2'
    classpath libs.jrdeps
  }
}

apply plugin: 'groovy'
apply plugin: 'com.github.gmazelier.jasperreports'

repositories {
    mavenCentral()
}

dependencies {
  compile libs.jrdeps
}

jasperreports {
  verbose = true
}

compileAllReports.dependsOn compileGroovy

Adding Project Compiled Sources

Use the classpath property to acces your compiled sources in you JasperReports designs. Configure your build script in a similar way:

jasperreports {
    verbose = true
    classpath = project.sourceSets.main.output
}

Getting Help

To ask questions or report bugs, please use the Github project.

Contributors

Patches are welcome. Thanks to:

Change Log

0.4 (2019-10-20)

  • Dependencies upgrade (Gradle and Jasper).
  • Move to Gradle publishing plugin.

0.3.2 (2015-12-07)

  • Adds Microsoft OS support.

0.3.1 (2015-11-24)

  • Fix an issue if there are multiple files in subdirectories when using useRelativeOutDir.

0.3.0 (2015-11-17)

  • Adds Java 8 support.
  • Configures Travis CI.
  • Improves tests.

0.2.1 (2015-04-03)

  • Adds useRelativeOutDir option.
  • Enable Gradle wrapper for developers.

0.2.0 (2015-02-26)

  • Adds classpath option.

0.1.0 (2014-08-24)

  • Initial release.

License

This plugin is licensed under Apache License, Version 2.0 without warranties or conditions of any kind, either express or implied.

gradle-jasperreports's People

Contributors

blaketastic2 avatar gmazelier avatar rankec avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gradle-jasperreports's Issues

Groovy language is not supported in report definition

Observed while reporting issue Classpath issues:

Change language in report definition from groovy to java to prevent the LinkageError or java.lang.NoClassDefFoundError: groovyjarjarasm/asm/ClassWriter error if groovy-all in not added in the buildscript configuration. It's a known workaround, see this comment on SO for example.

Prevent report compilation from creating icon for Gradle daemon on MacOS dock

When the report compilation runs, it exposes a Java icon on the MacOS dock. When using the gradle daemon, the icon will stay as long as the gradle daemon is alive.

The compilation needs to set the -Dapple.awt.UIElement=true on whatever process is being forked to do the compilation.

Setting the global export JAVA_TOOL_OPTIONS="-Dapple.awt.UIElement=true" does fix the problem, but is probably not the best solution since some apps may want to be on the dock.

classpath property not recognized

I tried the leaving untouched all of the default configuration property values, before I realized our classpath is not standard. So I tried replacing it, but I get:

No such property: classpath for class: com.github.gmazelier.plugins.JasperReportsExtension_Decorated

I even copy-pasted the default line on the project overview doc, and I get the same result.

dependency issue

Hi,

i tried to use your plugin but i got:

Error:Could not find com.lowagie:itext:2.1.7.js2.
Searched in the following locations:
https://jcenter.bintray.com/com/lowagie/itext/2.1.7.js2/itext-2.1.7.js2.pom
https://jcenter.bintray.com/com/lowagie/itext/2.1.7.js2/itext-2.1.7.js2.jar
Required by:
:Netversys3:unspecified > com.github.gmazelier:jasperreports-gradle-plugin:0.1.0 > net.sf.jasperreports:jasperreports:5.2.0

in the jcenter repos there is no "2.1.7.js2" folder but only "2.1.7".

Plugin not correctly finding source/out directory for multi-project build

This is the work-around so that I could make my project work. Note that I had to be explicit with the build directory.

jasperreports {
  val packageDir = "org/naic/spl/gateway/reports"
  val myBuildDir = project(":gateway-jasper-reports").buildDir
  srcDir = file("$projectDir/src/main/jasperreports/$packageDir")
  tmpDir = file("$myBuildDir/jasperreports")
  outDir = file("$myBuildDir/classes/java/main/$packageDir")
  srcExt = ".jrxml"
  outExt = ".jasper"
  compiler = "net.sf.jasperreports.engine.design.JRJdtCompiler"
  keepJava = false
  validateXml = true
  verbose = false
  useRelativeOutDir = true
  classpath = files
}

Documentation: tmpDir, outdir should use doubles quotes

There is an error in the documentation:

tmpDir = file('${project.buildDir}/jasperreports')
outDir = file('${project.buildDir}/classes/main')

This will create a directory called ${project.buildDir} in the project's main dir.

Example should use double quotes to specify tmpDir and outDir, in order to support String interpolation, replacing ${project.buildDir} with its value:

tmpDir = file("${project.buildDir}/jasperreports")
outDir = file("${project.buildDir}/classes/main")

Problem with dependency

Hi @gmazelier

This plugin is so cool. Are you still maintaining this? I have a problem with this plugin, got this error:

image

Could this because the outdated dependencies or some broken repository urls?

Classpath issues

I may be missing something silly here, but it looks like dependencies in the compile classpath are not used to execute the JasperCompileManager.

We are using some joda time classes in our reports, joda time is in the compile classpath, but we get the following sorts of errors:

    [InvoiceDepartment.jrxml] Errors were encountered when compiling report expressions class file:
  org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  General error during class generation: java.lang.NoClassDefFoundError: groovyjarjarasm/asm/ClassWriter

  java.lang.RuntimeException: java.lang.NoClassDefFoundError: groovyjarjarasm/asm/ClassWriter
    at org.codehaus.groovy.control.CompilationUnit.convertUncaughtExceptionToCompilationError(CompilationUnit.java:1083)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1061)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:583)
    at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:561)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:538)
    at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:109)
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:201)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:241)
    at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:157)
    at net.sf.jasperreports.engine.JasperCompileManager.compileToFile(JasperCompileManager.java:139)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:438)
    at net.sf.jasperreports.engine.JasperCompileManager$compileReportToFile$3.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at com.github.gmazelier.tasks.JasperReportsCompile$_execute_closure4_closure7.doCall(JasperReportsCompile.groovy:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:278)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1016)
    at groovy.lang.Closure.call(Closure.java:423)
    at groovy.lang.Closure.call(Closure.java:439)
    at groovyx.gpars.pa.CallClosure.call(CallClosure.java:47)
    at groovyx.gpars.pa.ClosureMapper.op(ClosureMapper.java:36)
    at groovyx.gpars.extra166y.AbstractParallelAnyArray$OOMPap.leafTransfer(AbstractParallelAnyArray.java:2255)
    at groovyx.gpars.extra166y.PAS$FJOMap.atLeaf(PAS.java:258)
    at groovyx.gpars.extra166y.PAS$FJBase.internalCompute(PAS.java:118)
    at groovyx.gpars.extra166y.PAS$FJBase.compute(PAS.java:106)
    at jsr166y.RecursiveAction.exec(RecursiveAction.java:148)
    at jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:305)
    at jsr166y.ForkJoinWorkerThread.execTask(ForkJoinWorkerThread.java:575)
    at jsr166y.ForkJoinPool.scan(ForkJoinPool.java:733)
    at jsr166y.ForkJoinPool.work(ForkJoinPool.java:617)
    at jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:369)
  Caused by: java.lang.NoClassDefFoundError: groovyjarjarasm/asm/ClassWriter
    at net.sf.jasperreports.compilers.JRGroovyCompiler$ClassCollector.call(JRGroovyCompiler.java:160)
    at org.codehaus.groovy.control.CompilationUnit$16.call(CompilationUnit.java:814)
    at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1047)
    ... 36 more

  1 error

    [InvoiceTitle.jrxml] Errors were encountered when compiling report expressions class file:
  org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  calculator_InvoiceTitle_1421861925896_293545: 168: unable to resolve class org.joda.time.LocalDate
   @ line 168, column 22.
  calculator_InvoiceTitle_1421861925896_293545: 232: unable to resolve class org.joda.time.LocalDate
   @ line 232, column 22.
  calculator_InvoiceTitle_1421861925896_293545: 296: unable to resolve class org.joda.time.LocalDate
   @ line 296, column 22.
  3 errors

Is this a known issue? I was able to work around it for now by adding the joda time dependency to the buildscript classpath:

buildScript {
  dependencies {
    classpath "joda-time:joda-time:2.3"
  }
}

Question about compiling with a custom expression function

I've followed the following tutorial and have no problem compiling a .jasper file in the Jaspersoft Studio. https://community.jaspersoft.com/wiki/jaspersoft-studio-expression-editor-how-extend-it-and-contribute-your-own-functions-part-2-0

I've defined a custom function and now I'm moving the project to Intellij. I'm using your plugin to compile the jasper file. But running into errors that my function is not recognized. Any information in how to go ahead with this? I've tried adding jasperreport-functions as dependency, but no help. Any ideas?

Plugin is not working anymore with Gradle 8

I do plan to upgrade to Gradle 8.

During the configuration step I get the following exception:

An exception occurred applying plugin request [id: 'com.github.gmazelier.jasperreports', version: '0.4']
> Failed to apply plugin 'com.github.gmazelier.jasperreports'.
   > Could not create task ':compileAllReports'.
      > Cannot use @TaskAction annotation on method JasperReportsCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.

I have seen that IncrementalTaskInputs is deprecated in Version 7.6.1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.