Build Java module and old jar for different Java versions from single source code

Viewed 205

I have Maven Java library project with target 1.8. I want to convert it into Java module for modern clients but keep backward compatibility for old clients, and publish new releases for both clients:

 my-mod   my-lib
 -v0.3    -v0.3
    \    /
     \  /
      \/
   my-lib-v0.2
       |
   my-lib-v0.1

So my questions is how to correctly add module-info.java into an existing project and be able to compile it to 1.8 target, and how to configure Maven to deploy two releases for two Java versions, e.g. for 1.8 and 17?

1 Answers

Just create your module-info.java inside your package folder. It will be ignored by Java 8 and picked up by Java 9+. Maybe you would like to take a look at this nice blog post: https://www.baeldung.com/java-9-modularity

Related