0

I'm trying to figure out how to use Maven to build a library jar file that is compatible with JDK 7 and 8 but includes a module-info.java file an explicitly declares its public API.

Problem: I need to compile for old target versions but the old JDKs obviously don't know the new JPMS features.

In this talk by Robert Scholte it seems like the best approach is to only compile the module-info file with JDK9. But how do I include it into the .jar then?

Any minimal example pom.xml would be of great help! :-)

Edit: Just to be clear: I don't get any compiler errors. I was just asking about the basic concept of using JPMS for JDK 9 users but keep my library backwards-compatible with JDK 7 and 8.

Sebastian S
  • 4,420
  • 4
  • 34
  • 63
  • 4
    https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html – ZhekaKozlov Dec 28 '17 at 09:59
  • module-info is only for JDK 9+...? – khmarbaise Dec 28 '17 at 10:06
  • You can include it, but not expect it to compile then(for JDK8 and prior). – Naman Dec 28 '17 at 10:08
  • Thanks, the link provided by @ZhekaKozlov answers my question. – Sebastian S Dec 28 '17 at 10:51
  • 2
    @nullpointer Other than your linked question, I am not talking about any compile time error, so how is this related? The link provided by ZhekaKozlov answers my question btw. – Sebastian S Dec 30 '17 at 16:34
  • @SebastianS Well I do agree on the point over the exact match but if you [look around](https://stackoverflow.com/a/45969290/1746118) in the same link, the sample has been shared. To cut short, the sample has been a part of the docs since the update of the plugin has been there for JDK9 compatibility. We can close this as Off Topic (...recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.) as well though. – Naman Dec 30 '17 at 16:40
  • 1
    @nullpointer I get your point and have no problem closing it as off topic. Imo, flagging it as duplicate of _that_ question is pretty misleading, though. Yes, there is an answer which contains the example from the maven docs, but both the question as well as the solution is vastly different. – Sebastian S Dec 30 '17 at 17:26

0 Answers0