gradlex-org/extra-java-module-info

Using 'mergeJar' leads to a build failure in subprojects that are unrelated to the merged Jar

nieqian1230 opened this issue · 3 comments

Hi Jendrik,

I am facing errors below when trying to use the plugin to resolve split package issue.

Could not isolate parameters org.gradlex.javamodule.moduleinfo.ExtraJavaModuleInfoTransform$Parameter_Decorated@295d2d44 of artifact transform ExtraJavaModuleInfoTransform
> Could not isolate value org.gradlex.javamodule.moduleinfo.ExtraJavaModuleInfoTransform$Parameter_Decorated@295d2d44 of type ExtraJavaModuleInfoTransform.Parameter
> Failed to query the value of property 'mergeJarIds'.
> Could not resolve all artifacts for configuration ':local-project:javaModulesMergeJars'.
> Could not find org.apache.zookeeper:zookeeper-jute:.
Required by:
project :local-project

I guess the problem may be due to nested dependency and duplicated dependencies. You can find the dependency tree for my project attached below.

image

Thanks,
Qiandong

The error indicates that the plugin cannot find a version for org.apache.zookeeper:zookeeper-jute:.

Which Gradle version are you using? If you use a version before 6.8, the plugin cannot automatically find versions from the runtime classpath because it uses the Consistent Resolution feature that was introduced in 6.8 for that (see this check in the code).

If possible, upgrade to the latest Gradle version (or at least latest 6.x).

A way to work around this in older versions can be:

configurations.javaModulesMergeJars {
    extendsFrom(configurations.runtimeClasspath.get())
}

Or use any other means to get the versions on the javaModulesMergeJars configuration. It depends on how you do version management in your project what the most elegant solution is. (E.g. defining dependency constraints for directly on the javaModulesMergeJars configuration, add a dependency to your java-platform project that contains all the versions, if you use that.)

If you are on the latest Gradle version, and still get the issue, I would ask you to please share a reproducer.

I think I stumbled over what might be the issue here. If you use the plugin in all your subprojects, but some of them do not have the "zookeeper" dependency at all it may fail there, because it still tries to get all the Jars-to-merge even if some are not needed at that place. I didn't see it in my examples, because they were either small or used consistent resolution or a platform project to make all versions available in all subprojects.

I'll have to come up with a reproducer and see if this issue can be avoided.

In your case, as a workaround, you could add the Jute version explicitly in all projects. So basically in the place where you applied the plugin, add this afterwards:

dependencies.constraints {
  javaModulesMergeJars("org.apache.zookeeper:zookeeper-jute:3.6.2")
}

Turns out that this was indeed a bug. Will be fixed in 1.1 (I will release that soon). Thanks @nieqian1230 for making me aware of this!