I'm trying to figure out how can I share packages between two modules in a single IntelliJ project, and I can't seem to find the right way to do it. I know it can be done in Eclipse, but I'm not very well-versed with it. In a nutshell, I'm trying to reproduce the same kind of project environment created by AppEngine-connected Android projects.
Here's the "problem" as best I can lay it out
Project A.
Each module has its own source directory within the Project's main directory:
I create packages for both modules, and write the various classes needed for each. Most classes are unique to the module / platform, and are packaged into their own namespace
Module 1
Module 2
However, there are some identical Interfaces and Enums that I use within both modules: Now I'd like to have all my identical code in a single package shared between the two, so I don't have to copy the source between packages every time I change something around.
I know IntelliJ will allow you to configure multiple content Roots as part of a module's configuration. But it doesn't seem that two modules care share the same content root if their part of the same IntelliJ Project...? Is there a better way to configure my project? Or am I missing something..?
Import an existing moduleFrom the main menu, select File | New | Module from Existing Sources. In the dialog that opens, specify the path the . iml file of the module that you want to import, and click Open. By doing so, you are attaching another module to the project without physically moving any files.
A Module can reference a library which can be a project library or a global library. Global libraries have to be defined only once. Project library in every project you need them. Packages are a java concept and are IDE independent.
You could move shared code into another module that has its own content root, say:
/ProjectA/Module3/src
and then add a module dependency on Module3 to both Module1 and Module2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With