How do I create sub projects in my Java project? (original) (raw)
December 1, 2025, 1:57pm 1
This maybe a bit of a silly question, but I never bothered to find out how I should setup sub projects in my Java-project and it is becomming a mess now.
Here is the scenario: I am working on a new project, a game. To create content for this game, I want to create a number of editors. I think these editors should be sub projects in my main project, but I have no clue how to set this up.
Can someone recommend to a good (video) guide to learn how to do this?
richtea December 1, 2025, 2:22pm 2
What build system are you using? If it’s gradle you can create a new gradle module
kruze December 1, 2025, 3:02pm 3
You usually use a build system like Gradle or Maven. Both these support creating subprojects or submodules. You can check their documentation online.
In general you will have a root folder for your project and then your subprojects will have their own folders. I’m a Maven guy and I also do subprojects. Example:
my-game-project-folder/
sub-project-server/
pom.xml
sub-project-client/
pom.xml
sub-project-common/
pom.xml
sub-project-editor/
pom.xml
pom.xml
Then in my pom file I list them as modules so Maven knows they are submodules.
<modules>
<module>sub-project-server</module>
<module>sub-project-client</module>
<module>sub-project-common</module>
<module>sub-project-editor</module>
</modules>
Then in sub-project-server if I need stuff from sub-project-common I can add it as a dependency:
<dependencies>
<dependency>
<groupId>com.myproject</groupId>
<artifactId>sub-project-common</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
For Gradle it’s similar but on the Gradle way (meaning you need to edit different files).
Gradle Docs - Multi Project Builds
Maven - Multi Module Builds
pspeed December 1, 2025, 3:49pm 4
And for sub-projects, gradle has the advantage that they are genuine sub-projects and not just some hacked in wiring around “separate projects in the same directory structure” like for maven.
If you rebuild just a gradle subproject, it knows which other sub-projects to rebuild and tracks the dependencies for it correctly.
It’s possible that if you use an IDE then it will gloss over some of maven’s multi-project ugliness but it will never be as good at gradle is at tracking dependencies.
So if you are still in the “undecided” camp, gradle is the more modern option.
If you are already using gradle, you probably already have a settings.gradle file in the root. After creating the sub-project subdirectories, add new subprojects in settings.gradle. To have one sub-project depend on another, add the dependency in build.gradle like for any other jar except use project(:foo:bar) as the dependency.
Here is an example of a settings.gradle file for a simple multi-project build:
…it has the advanced application of renaming the sub-project, too… if for some reason you want/need different sub-directory names than sub-project names.