Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to derive module descriptor during generateModuleInfo #12

Open
nemphys opened this issue Jun 1, 2020 · 4 comments
Open

Unable to derive module descriptor during generateModuleInfo #12

nemphys opened this issue Jun 1, 2020 · 4 comments

Comments

@nemphys
Copy link

nemphys commented Jun 1, 2020

I am trying to generate module-info for JasperReports (artifact 'net.sf.jasperreports:jasperreports:6.12.2') using the latest version (rc1).

The error is:
Unable to derive module descriptor for /Users/xxxxxx/.gradle/caches/modules-2/files-2.1/org.apache.xmlgraphics/batik-script/1.11/f7284dabc28aaa7407bef45f31dd204e58a35810/batik-script-1.11.jar

@siordache
Copy link
Member

Running gradle with the --stacktrace switch, you will see:

...
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.batik.bridge.RhinoInterpreterFactory not in module

batik-script-1.11.jar is broken and the plugin cannot help in this case. You will get the same error when running:

jar -d -f batik-script-1.11.jar

See also this batik issue.

Possible workarounds (not sure if they really work):

  • fix batik-script-1.11.jar by removing the org.apache.batik.bridge.RhinoInterpreterFactory entry from META-INF/services/org.apache.batik.script.InterpreterFactory.

  • patch batik-bridge-1.11.jar into batik-script

@nemphys
Copy link
Author

nemphys commented Jun 2, 2020

OK, I just had this secret hope that you might come up with a simple one-liner for this :-)

@siordache
Copy link
Member

siordache commented Jun 2, 2020

Nothing close to a one-liner. Just an ugly workaround:

configurations {
    broken
}
dependencies {
    broken 'org.apache.xmlgraphics:batik-script:1.11'
    broken 'xalan:xalan:2.7.2'
}

tasks.addDependenciesModuleInfo.doFirst {
    fixJar('batik-script', 'org.apache.batik.script.InterpreterFactory', 'org.apache.batik.bridge.RhinoInterpreterFactory')
    fixJar('xalan', 'org.apache.xalan.extensions.bsf.BSFManager', 'org.apache.bsf.BSFManager')
    // ... additional calls to fixJar are probably needed
}

def fixJar(String jarPrefix, String service, String brokenImpl) {
    configurations.broken.files.findAll { f ->
        f.name.startsWith jarPrefix
    }.each { brokenJar ->
        def destDir = file("$buildDir/broken")
        delete destDir
        mkdir destDir

        def zt = zipTree(brokenJar)
        def expandedPath = zt.asFileTree.tree.mirror.dir.path
        def files = zt.files.each { f ->
            def pathInJar = (f.path - expandedPath).substring(1)
            def destFilePath = destDir.toPath().resolve(pathInJar)
            mkdir destFilePath.parent
            java.nio.file.Files.copy(f.toPath(), destFilePath)
        }
        def svcFile = destDir.toPath().resolve("META-INF/services/$service").toFile()
        def newText = svcFile.text.replace(brokenImpl, '')
        svcFile.text = newText

        delete brokenJar
        def jarExec = java.util.spi.ToolProvider.findFirst( "jar" ).get()
        def result = jarExec.run(System.out, System.err,
            '-cf', "$brokenJar.path", '-C', destDir.path, '.')
        println "Fixed $brokenJar"
    }

}

@nemphys
Copy link
Author

nemphys commented Jun 3, 2020

Wow, thanks. I will try it as soon as I find the time and report back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants