Multi-release jar files without multiple sets of source code

400 Views Asked by At

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>
1

There are 1 best solutions below

0
On

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.