ChrisHegarty commented on a change in pull request #470: URL: https://github.com/apache/lucene/pull/470#discussion_r765798599
########## File path: gradle/java/modules.gradle ########## @@ -199,6 +200,67 @@ allprojects { } } + // Configure the test task. + tasks.matching { it.name == "test" }.all { Test task -> + Configuration modulePath = task.project.configurations.maybeCreate("moduleTestCompilePath") + task.dependsOn modulePath + + SourceSet sourceSet = task.project.sourceSets.test + + Predicate<SourceSet> hasModuleDescriptor = { SourceSet ss -> + ss.allJava.srcDirs.stream() + .map(dir -> new File(dir, "module-info.java")) + .anyMatch(file -> file.exists()) + } + + // Add modular dependencies and their transitive dependencies to module path. + task.jvmArgumentProviders.add(new CommandLineArgumentProvider() { + @Override + Iterable<String> asArguments() { + def extraArgs = [] + + // Determine whether the source set classes themselves should be appended to classpath + // or module path. + boolean sourceSetIsAModule = hasModuleDescriptor.test(sourceSet) + + if (!modulePath.isEmpty() || sourceSetIsAModule) { + if (sourceSetIsAModule) { + // Add source set outputs to module path. + extraArgs += ["--module-path", (modulePath + sourceSet.output.classesDirs).files.join(File.pathSeparator) ] + // TODO: we should only initially add the sourceset's module? Everything else would be resolved via the Review comment: @dweiss Correct, the name of the module under test should be sufficient here, rather than ALL-MODULE-PATH. But since we carefully control what is on the module path, then I see no issue with using ALL-MODULE-PATH. Extracting the module name from a module-info.class is easiest achieved with the Java API, but I see your point about the Gradle-in-use-for-java-test version being possibly less than that of the compiled module, which will end in something like `InvalidModuleDescriptorException: Unsupported major.minor version ..`. I guess we could parse the module-info.java file, but that seems a little hacky! ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org