Which version of iText to use so that both JasperR

2019-02-17 22:28发布

问题:

I want to use both Jasper Reports (vanilla, never got the Grails Jasper plugin to work - see this) and Grails Rendering plugin (one is more suitable for some reports, another for others).

If I include 'com.lowagie:itext:2.1.5' or 'com.lowagie:itext:4.2.1' then I am missing com.lowagie.text.pdf.BaseFont.getCharBBox upon running the Rendering plugin's PDF report.

If I include 'com.lowagie:itext:2.0.8' then I am missing com.lowagie.text.pdf.PdfWriter.setRgbTransparencyBlending upon running Jasper's PDF report.

Both are failing with java.lang.NoSuchMethodError-s.

I haven't tried with the latest iText versions, but they have different package names and more restrictive licensing, so I don't think they would be a good fit.

My BuildConfig.groovy looks like this (one of the first 3 dependencies gets uncommented):

dependencies {
  // runtime 'com.lowagie:itext:4.2.1' // missing.BaseFont.getCharBBox
  // runtime 'com.lowagie:itext:2.0.8' // missing PdfWriter.setRgbTransparencyBlending
  // runtime 'com.lowagie:itext:2.1.5' // missing.BaseFont.getCharBBox  
     compile 'net.sf.jasperreports:jasperreports:5.2.0' // needed by jasper
     runtime 'org.springframework:spring-test:3.2.4.RELEASE' // needed by rendering plugin
     runtime 'commons-collections:commons-collections:3.2.1' // needed for jasper            
}

plugins {
    // ...
       compile ":rendering:0.4.4"
    // compile ":jasper:1.6.1" // couldn't get this to generate anything, but not sure it would help any
    // ...
}

Is there any "old" version of iText (MPL-licensed) that I could try that may work?

Is there some way to ask Maven/Gradle to make it so that I can ask one of the libraries/plugins to use one version of iText, and another the other?

回答1:

The solution is to use the "excludes" clause when including the rendering plugin:

compile(":rendering:0.4.4") {
        excludes(
            [group:'org.xhtmlrenderer'],
            [group:'com.lowagie']
        )
    }

This doesn't really solve all issues as there is an old version of org.xhtmlrenderer Flying Saucer core-renderer-R8.jar included with Grails itself (depended upon by grails-docs), but it does answer this particular question about how to get the iText dependency to work (along with the excludes I simply included 'com.lowagie:itext:2.1.7' and it worked for both Jasper and rendering plugin.