question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve separate compilation of module-info.java

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
siordachecommented, Aug 14, 2019

Thanks for the great analysis, Tomasz! Option 2.b is my favorite. I will implement it in the next couple of days.

1reaction
tlinkowskicommented, Aug 14, 2019

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):

  1. [Compile+Run] Compile everything (Kotlin, Java, Groovy, module-info - in that order) into a single directory so that “module-info” sees all the packages when we compile and then test/run
    • pros: simple
    • cons: hard to clean, hard to cache by Gradle
  2. [Compile] Compile everything separately using the --patch-module trick (nice!) [Run] “Merge” the output into a separate single directory (e.g. build/classes/merged) for the purposes of test and run tasks
    • pros: separate dirs can be cleaned & cached in Gradle
    • cons: more complicated - I see two options here
      1. test and run mark those separate dirs as their input (build/classes/java|kotlin|groovy|module-info), and only during doFirst, for their internal purposes, they perform: 1) purging build/classes/merged (in case it contains something stale), 2) copying contents of build/classes/java|kotlin|groovy|module-info into build/classes/merged
      2. we introduce a separate task of type Sync, named e.g. mergeClasses, on which run and test depends, and which:
        • depends on: compileKotlin, compileJava, compileGroovy, compileModuleInfoJava
        • inputs (from): separate dirs (build/classes/java|kotlin|groovy|module-info)
        • output (into): build/classes/merged
        • thanks to having a separate task, we leave it to Gradle to determine if build/classes/merged has anything stale or not

To 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature request: Separate compilation of module-info.java #72
Overview I'd like to request a feature for library developers who need to target JDK 6-8 but who also want to provide a...
Read more >
Java 9+ modularity: How to design packages and create ...
Compile, JAR, and run the main module; Examine a module-dependency diagram. First steps to take to develop the modules. Open your IntelliJ IDEA ......
Read more >
Handle separate compilation of module-info.java - Apache
Handle separate compilation of module-info.java ... Java it is probably better to just have a separate folder for it, e.g. src/main/jigsaw.
Read more >
Java Modules - Jenkov.com
A Java module is a packaging mechanism that enables you to package a Java application or Java API as a separate Java module....
Read more >
Compile a JDK 8 project + a JDK 9 "module-info.java" in Gradle
java with --release 8 ). Ant. E.g. Lombok (their approach boils down to: have module-info.java in a separate "source set" - ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found