Do I still need maven dependencies when using JPMS modules?

  Kiến thức lập trình

I don’t fully understand the combination of JPMS and maven. In multiple places, the two claim to be independent and orthogonal to each other, yet both offer concepts for dependency and encapsulation.

Our Setup

We currently have a code base consisting of multiple maven projects that are referencing each other by using maven dependencies. We don’t use maven modules.

We now wish to extract some functionality of one of the projects, which may be eventually even released as a public library. For this, we want to see if using JPMS modules would give us benefits. From what I’ve read so far (see here and there), strong arguments include better encapsulation, and I can understand that using the JPMS export statements etc. enable hiding classes that are not meant for the user of the library.

We extracted the affected code and placed it in a separate maven project, added a, and only exported the relevant class.

What confuses me

My confusion now starts when we wanted to use this library in our legacy code, where we have extracted the library from. This code does not use JPMS. From what I’ve understood, we could just add the new library maven project as dependency, but this would not grant us the benefits of JPMS, as all classes of the library then could be used by the consuming application right? I’ve also tried to add the library as module using a maven-compiler-plugin configuration as described here, but that seems very cumbersome.

I understand that ideally, our main application would also use JPMS, and we could add the dependency in the, but this is no option at the moment.

I have the feeling that I’m missing a bigger point, so I’d welcome a fundamental explanation of the issue at hand.