Common source code in two modules

Answered

My question is - is there a way in IntelliJ to use the same source code (java) in two modules/source sets? 

- we have quite a huge project, a LOT of code, 3rd party libraries, Gradle, often client-server

- our goal is to modularise it for Java 11 in order to have smaller client self-packaged app

- our typical IntelliJ module consists of three dirs 

     - server

     - common

     - client

- source sets in Gradle are organised so that

      - final server jar uses server and common sources

      - final client jar uses client and common sources

One way to go would be to produce three Java modules for each IntelliJ module - server.jar, common.jar and client.jar, however that would mean a LOT of refactoring (server, client and common often use the same package name - not a good idea, I know, but that's the way it is) due to resulting split packages. If possible, I would like to avoid the refactoring.

Thanks for any hints!

0
3 comments

3 modules is the way to go. You can use Gradle source sets or composite builds. Refactorings should be straightforward and handled by the IDE and you are not required to change the package names.

0
Avatar
Permanently deleted user

Thanks for a prompt answer. However - "and you are not required to change the package names"  - this part I don't understand. Client.jar and common.jar can not have the same package names in modularised Java 9+ app. 

0

Oh, you are right. In that case you will have to refactor the package names, but IDE should rename all the references automatically, so it's not a big issue.

0

Please sign in to leave a comment.