2

I've a maven multi module project in following structure. Our project is in GitHub corporate page.

I'm planning to make one of the maven module project public to let it be open source. However, because of maven multi-module project structure it needs to be under parent project hierarchy in file system, isn't it ?

What I want to do is creating a separate repository for publicModule2 and pushing it to public repo. It'll be an open source project. The rest will remain the same. Is there any way doing it without breaking maven multi module project structure ?

-- Maven parent project

  • -- commonsModule
  • --cusomModule1
  • --cusomModuleN
  • --publicModule2

P.S.As you know when you remove it from modules they're not compiling together each time and I don't want this. Without module structure I already separated another project but I don't look for that for this project. Please consider this in your reply

Davut Gürbüz
  • 5,526
  • 4
  • 47
  • 83

1 Answers1

1

If you are serious about making it open source, that includes giving people an easy, reproducible way to build it. If it is required to be built as part of a larger project which they don't have access to, they won't be able to do that.

What you are looking for is possible with Git submodules. You would need to make the public one a submodule of the original parent.

From the docs, this feature is to be used when

you want to be able to treat the two projects as separate yet still be able to use one from within the other.

However I would strongly advocate separating the projects so that the public one can be built independently.

Michael
  • 41,989
  • 11
  • 82
  • 128
  • Thanks @Michael. For my case there is no dependency to any other project from the submodule. I'm already able to build submodule alone. I've just skimmed Git submodules. It sound Git submodules will solve my problem. I don't want to break multi-module structure in overall solution to see if there's any breaking change in that up-to-date submodule in every compilation. – Davut Gürbüz Jul 02 '20 at 12:19
  • Because in that project pom I removed part and it still compiles all when I compile parent. – Davut Gürbüz Jul 02 '20 at 12:23
  • `After all, if we wish to share all the configuration with our submodules, in their pom.xml files, we'll have to declare the parent` . I'm not planning to share something from parent to submodule. So, it'll be totally independent, right ? Am I missing a defect ? – Davut Gürbüz Jul 02 '20 at 12:29
  • @DavutGürbüz Usually the main benefit of structuring a Maven project in this way is so you can easily inherit configuration from the parent. If your project is totally distinct and does not rely on the parent, you are not really using any of the benefits of multi module setup (for this module at least). So begs the question why not just move it to a standalone project and add a dependency to your existing one. – Michael Jul 02 '20 at 12:32
  • @Michal Right. Basically when I compile parent project I want current submodule code be compiled, too. It's happening so now. Apart from it I don't get parent versionid or any other shared prop etc. – Davut Gürbüz Jul 02 '20 at 12:34
  • 1
    It worked just as I wished with git submodules. I just cloned from empty repo in the beginning and it caused some wrong git indexes creation but SO helped me one more time https://stackoverflow.com/a/35778105/413032 – Davut Gürbüz Jul 02 '20 at 14:29