Improve separate compilation of module-info.java
See original GitHub issueI implemented compileModuleInfoJava
task by making its destinationDir
to be the same as that of compileJava
task. Since then, I learned (thx, @sormuras!) that Gradle task shouldn’t share the same output directories (it’s problematic e.g. for cleaning or caching).
A much cleaner solution would be to change this: https://github.com/java9-modularity/gradle-modules-plugin/blob/44a76f62965d93a45422f62f16fb75ef6e3fe13d/src/main/java/org/javamodularity/moduleplugin/tasks/CompileModuleInfoTask.java#L60-L62
to sth like this:
compileModuleInfoJava.setClasspath(project.files(compileJava.getDestinationDir()));
compileModuleInfoJava.setSource(pathToModuleInfoJava());
compileModuleInfoJava.setDestinationDir(/* e.g. `build/module-info` */);
and then making the Jar
task include the destinationDir
of compileModuleInfoJava
task.
It’s based on what @sormuras did while implementing https://github.com/junit-team/junit5/pull/1857: https://github.com/junit-team/junit5/blob/8484eaeff1e0bbd4536ff262c2394972945296cf/buildSrc/src/main/kotlin/java-library-conventions.gradle.kts#L85-L93
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
Thanks for the great analysis, Tomasz! Option 2.b is my favorite. I will implement it in the next couple of days.
Ha, so it’s actually much harder than I assumed… Thanks for your excellent research and work, Serban!
I read what you linked. As I see it now, we have the following two options (correct me if I’m wrong):
--patch-module
trick (nice!) [Run] “Merge” the output into a separate single directory (e.g.build/classes/merged
) for the purposes oftest
andrun
taskstest
andrun
mark those separate dirs as their input (build/classes/java|kotlin|groovy|module-info
), and only duringdoFirst
, for their internal purposes, they perform: 1) purgingbuild/classes/merged
(in case it contains something stale), 2) copying contents ofbuild/classes/java|kotlin|groovy|module-info
intobuild/classes/merged
Sync
, named e.g.mergeClasses
, on whichrun
andtest
depends, and which:compileKotlin
,compileJava
,compileGroovy
,compileModuleInfoJava
from
): separate dirs (build/classes/java|kotlin|groovy|module-info
)into
):build/classes/merged
build/classes/merged
has anything stale or notTo sum up, I think I still prefer option 2 over option 1, and as I can’t think of anything better than copying, I tried to analyze how to approach this copying best.