javaandroidgradlejavafx

Project with path ':module2' could not be found in root project 'javafx'


I'm creating multi project in Java with Gradle build tool. My purpose is to working with JavaFx and Android using modules in the multi project. Like

multiproject\
-javafx\
--build.gradle
--settings.gradle
-module1\
--build.gradle
-module2\
--build.gradle

But I'm encountering the problem that I can't build the JavaFx, it shows

A problem occurred evaluating root project 'javafx'.
> Project with path ':module2' could not be found in root project 'javafx'.

/javafx/build.gradle

dependencies {
  implementation project(":module2")
  testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
  testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
}

and in the root project settings.gradle

rootProject.name = 'multiproject'
include 'module1', 'javafx'
include 'module2'

I want to use the modules outside of JavaFx or Android project instead of creating modules inside each project.
And why I don't pack the modules to maven or gradle that I'm still developing the modules belong the project.

Sorry for my bad English, Thanks!


Solution

  • Your directory layout and the contents of your settings.gradle file suggest that "multiproject" is supposed to be the root project. But the error shows that Gradle thinks your root project is "javafx". Which means something is wrong with your setup/configuration. Looking at your directory layout:

    multiproject\
    -javafx\
    --build.gradle
    --settings.gradle
    -module1\
    --build.gradle
    -module2\
    --build.gradle 
    

    You appear to have your settings.gradle file under the multiproject/javafx/ directory. There is supposed to be at most one settings file per build, and that file should be at the root of the entire project. In short, you need to move your settings file up one directory to be under multiproject/.

    More visually, your project's directory layout currently looks like this:

    multiproject\
    +---javafx\
    |       build.gradle
    |       settings.gradle
    |
    +---module1\
    |       build.gradle
    |
    \---module2\
            build.gradle
    

    But should actually look more like this:

    multiproject\
    |   settings.gradle
    |
    +---javafx\
    |       build.gradle
    |
    +---module1\
    |       build.gradle
    |
    \---module2\
            build.gradle