gradlex-org/extra-java-module-info

Question on trying to use mergeJar feature.

Closed this issue · 3 comments

Unfortunately I'm stuck in a split package scenario with java.annotations and jsr305-3.0.2.jar. This is all legacy code I can't really change but trying to get modularized.

When I run my builds when I force the jars onto the module path I see I get split package like errors..
error: the unnamed module reads package javax.annotation from both jsr305 and java.annotation
error: module velocity.engine.core reads package javax.annotation from both jsr305 and java.annotation
... others too

I'm wondering what is the right way to fix this with the mergeJar?

here's a gradle snippet of what I'm trying to do..

extraJavaModuleInfo {
// these work fine! Thanks!!
automaticModule("org.apache.poi:poi", "poi")
automaticModule("org.apache.poi:poi-ooxml", "poi.ooxml")
// don't think I want this?? but this give me the ability to see the split jar issue
automaticModule("com.google.code.findbugs:jsr305", "jsr305")

// this doesn't seem right?
// automaticModule("com.google.code.findbugs:jsr305", "jsr305") {
// mergeJar("javax.annotation")
// }

// I assume i want to do something like this? but not sure what group name is?
// automaticModule("javax.annotation", "javax.annotation") {
// mergeJar("jsr305")
// }

failOnMissingModuleInfo.set(false) // need this or it will want to force all other transitive JARs as well
}

I'm wracking my brains trying to understand how to just get the jsr305 'merged' into whatever the base JAR is that defines javax.annotation..

Thanks!!!

Yes the GroupArtifact Coordinates vs Module Name is often very confusing. Especially when the names differ. I hope our plugins help to clear up confusion here in the future but we probably can't auto-fix everything. I faced the split package with javax.annotation as well in a project. You probably need this:

automaticModule("com.google.code.findbugs:jsr305", "java.annotation") {
  mergeJar("javax.annotation:javax.annotation-api")
}

Or something like this if you want it to be a "real" module:

module("com.google.code.findbugs:jsr305", "java.annotation") {
  mergeJar("javax.annotation:javax.annotation-api")
  exports("javax.annotation")
  exports("javax.annotation.concurrent")
  exports("javax.annotation.meta")
}

Thanks for the quick help..

This is what I was able to get to work for that project.

// google jsr305 causes a split package issue with the javax.annotation module so we need
// to explicitly merge it into the other one. After trial/error it appears like this jakarta defines this
// within our project
automaticModule("jakarta.annotation:jakarta.annotation-api", "javax.annotation") {
mergeJar("com.google.code.findbugs:jsr305")
}

Thanks so much! This plugin is super helpful for all these legacy scenarios.

This example actually revealed a bug in the Jar merging: #50