-2

I want to create a multi-release JAR file for a library. I will build the MRJAR using maven - and initially it will contain Java 8 and Java 9 class files.

BUT - I do not want to maintain two separate sets of source code (e.g. in src/main/java-8 and src/main/java-9). Is it possible to have all of the Java-9 files in e.g. src/main/java and only the ones which differ in e.g. src/main/java-8 ?

Ideally, the full source code would then be organized as:

+ pom.xml
+ src
  + main
    + java
      <full java-9 source code>
    + java-8
      <overriding .java files which can only be compiled with java-8>
tbsalling
  • 4,477
  • 4
  • 30
  • 51
  • 1
    Did you read the Maven document about handling Multi Release jar files? A simple web search for [`maven multi-release jar`](https://www.google.com/search?q=maven+multi-release+jar) lead right there: https://maven.apache.org/plugins/maven-compiler-plugin/multirelease.html. --- The search also found many good articles on the subject. – Andreas Nov 05 '19 at 09:39
  • @Andreas - yes I did, mr. Grumpy. But the article is all about .class files. Not .java files. – tbsalling Nov 05 '19 at 09:49
  • 1
    https://docs.oracle.com/en/java/javase/13/docs/specs/jar/jar.html#multi-release-jar-files – Slaw Nov 05 '19 at 09:56
  • Doesn’t sound like a useful setup for multi-release jar. In order to use your software under Java 8, *all* needed classes must be available in a Java 8 compatible way. So the natural setup would be to have a full java-8 source code folder and a patch folder containing overriding files using java-9 features. It would match the way, the resulting jar is organized, all classes be put into the root (java-8 compatible) and a version specific folder containing the overriding classes for java-9+. I suggest tagging the question with `[maven]` to attract the experts to tell you how to do it with maven. – Holger Nov 06 '19 at 10:52
  • Thanks @Holger - I will try to pursue this. – tbsalling Nov 06 '19 at 14:49

1 Answers1

2

I do not want to maintain two separate sets of source code

You have to, so you can compile the Java 8 files separately from the Java 9 files.

Implied in the question (the way I read it), but not explicitly stated, is that you have two copies of the files that don't differ. You certainly don't need that.

Is it possible to have all of the Java-9 files in e.g. src/main/java and only the ones which differ in e.g. src/main/java-8 ?

That wouldn't make any sense, because all the files that don't differ must be Java 8 files, not Java 9 files.

Do the opposite.

Andreas
  • 154,647
  • 11
  • 152
  • 247