Home > Net >  Multiple projects within one gradle project
Multiple projects within one gradle project

Time:10-23

I could not find any hints on how to do this in the gradle documentation because I'm still a beginner at working with Java and Gradle.

I'm currently using IntelliJ IDEA and I want to create an application with a backend and frontend where both of them are able to stand alone. Inside my project explorer my current project looks like this:

enter image description here

Stockie is the main class and depends on the Indicators class and I want to create a second app called Stockie-Frontend which will be a JavaFX application itself.

Where should I put this according to convention?

Many thanks in advance.

CodePudding user response:

You need check this link on own gradle docs: https://docs.gradle.org/current/userguide/multi_project_builds.html

You need need put both project into a root folder:

.
├── build.gradle    # all configurations for all modules, projects
├── settings.gradle # declaring all modules
│
├── stockie        # module 1
│   ├── src/main/java
│   └── build.gradle # build.gradle file from module 1
│
│
└── stockie-front # module 2
    ├── src/main/java
    └── build.gradle # build.gradle file from module 2

declare all module in settings.gradle from root folder contains all module folder

include (
    "stokie", // name module 1 ( same name folder )
    "stockie-front" // name module 2 ( same name folder )
)

if you need import any module into other module as dependencie add in new-module-folder/build.gradle

dependencies {
   implementation project(":my-module") // start with :
   implementation project(":stokie") //eg. import stokie module into new-module-folder
}

running task in root folder

gradle build # will build all modules
gradle :stokie:build # build only stokie module
gradle :stokie:clean build # clean and build only stokie module
  • Related