Search code examples
gradlegradle-pluginmulti-project

Multi-project failed to build in Gradle-4.2.1


I am migrating my project to use Multi-project structure . Currently I am using Gradle-4.2.1. When I configure the gradle throws below exception

Exception:

FAILURE: Build failed with an exception.

  • What went wrong: Could not normalize path for file 'D:\User\Project2:Subproject1'.

    The filename, directory name, or volume label syntax is incorrect

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

  • Get more help at https://help.gradle.org

CONFIGURE FAILED in 0s

My project structure

-root -Project1 -build.gradle

-buildProject
-build.gradle
-settings.gradle 

-Project2 
-build.gradle
    -Subproject1
    -build.gradle
    -Subproject2
    -build.gradle

-Project3
-build.gradle

Below is the settings.gradle looks like

includeFlat 'Project1' includeFlat 'Project2' includeFlat 'Project2:Subproject1' includeFlat 'Project2:Subproject2' includeFlat 'Project3'

I have below questions.

Am I am using correct gradle version (supports multi-project structure)? Is My project structure correct? Any other changes needed to in the settings.gradle to build the project successfully?


Solution

  • I think you should use include "Project2:Subproject1", not includeFlat, in order to include nested subprojects. If you read the official documentazion here, you can read

    The includeFlat method takes directory names as an argument. These directories need to exist as siblings of the root project directory. The location of these directories are considered as child projects of the root project in the multi-project tree

    include works fine with nested subprojects:

    The project path is assumed to be equal to the relative physical file system path. For example, a path 'services:api' is mapped by default to a folder 'services/api'

    I hope this can help you to solve the problem!