java9-modularity / gradle-modules-plugin

This Gradle plugin helps working with the Java Platform Module System
https://javamodularity.com/
MIT License
233 stars 36 forks source link

"Module ___ not found" for `run` task (Java 11 with Kotlin/Groovy plugin applied) #118

Open tlinkowski opened 5 years ago

tlinkowski commented 5 years ago

When targeting JDK 11, in a project that has Java, Kotlin, and Groovy plugins applied but has only Java sources, run task fails with:

java.lang.module.FindException: Module ___ not found

It seems to be due to:

Example

This behavior is exemplified on a branch of my project, where run fails like below: https://travis-ci.com/tlinkowski/UniJ/builds/127633638#L1234-L1236

For a module targeting JDK 8, it works fine, though: https://travis-ci.com/tlinkowski/UniJ/jobs/235293201#L1271-L1273

In a debugger, I managed to find out that for JDK 11, run is instrumented with the following command line arguments:

--module-path [...]\UniJ\subprojects\api\pl.tlinkowski.unij.api\build\libs\pl.tlinkowski.unij.api-0.1.0-SNAPSHOT.jar;C:\Users\tlink.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-simple\1.7.28\cf5f2cf3c31e0e41b68d932d756398a1238d4456\slf4j-simple-1.7.28.jar;[...]\UniJ\subprojects\bindings\collect\pl.tlinkowski.unij.service.collect.jdk10\build\libs\pl.tlinkowski.unij.service.collect.jdk10-0.1.0-SNAPSHOT.jar;[...]\UniJ\subprojects\bindings\misc\pl.tlinkowski.unij.service.misc.jdk11\build\libs\pl.tlinkowski.unij.service.misc.jdk11-0.1.0-SNAPSHOT.jar;[...]\UniJ\subprojects\samples\enduser\pl.tlinkowski.unij.sample.enduser.jdk11\build\classes\merged;[...]\UniJ\subprojects\bundles\pl.tlinkowski.unij.bundle.jdk11\build\libs\pl.tlinkowski.unij.bundle.jdk11-0.1.0-SNAPSHOT.jar;[...]\UniJ\subprojects\api\pl.tlinkowski.unij.service.api\build\libs\pl.tlinkowski.unij.service.api-0.1.0-SNAPSHOT.jar;C:\Users\tlink.gradle\caches\modules-2\files-2.1\org.slf4j\slf4j-api\1.7.28\2cd9b264f76e3d087ee21bfc99305928e1bdb443\slf4j-api-1.7.28.jar;[...]\UniJ\subprojects\samples\enduser\pl.tlinkowski.unij.sample.enduser.jdk11\build\resources\main -agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=50721 --patch-module pl.tlinkowski.unij.sample.enduser.jdk11=[...]\UniJ\subprojects\samples\enduser\pl.tlinkowski.unij.sample.enduser.jdk11\build\resources\main --module pl.tlinkowski.unij.sample.enduser.jdk11/pl.tlinkowski.unij.sample.enduser.jdk11.EndUsage

As you can see, we have build\classes\merged which shouldn't be there according to the spec from #101. However, :pl.tlinkowski.unij.sample.enduser.jdk11:mergeClasses task was not run (and was not present, which I confirmed in the debugger).

Conclusions

Because we:

  1. don't have mergeClasses tasks
  2. have build/classes/merged on the module path

it seems to me that the two calls to isMergeRequired return different results:

  1. returns false: https://github.com/java9-modularity/gradle-modules-plugin/blob/29d5d8db84258a1e1199a79f9017fad7c3437692/src/main/java/org/javamodularity/moduleplugin/tasks/MergeClassesTask.java#L19-L22

  2. returns true: https://github.com/java9-modularity/gradle-modules-plugin/blob/5e49c01f49a6e830c64b29f31eba0f064cf1d45d/src/main/java/org/javamodularity/moduleplugin/tasks/MergeClassesHelper.java#L65-L68

I haven't yet confirmed if they really do return different results, and - if so - why it happens.

yuliu2016 commented 4 years ago

I believe that I have had the same/a related issue, since changing the version to 1.6.0 in my project - build/classes/merged is now part of the module-path while build/classes/java and build/classes/kotlin are now not part of the module-path (which it was when I used 1.5.0)