I have a root project gradletinker with sub-module xt-domain-layer. The settings.gradle of gradletinker is:
rootProject.name = 'gradletinker'
include 'xt-domain-layer'
The xt-domain-layer also contains a submodule called xt-web. The settings.gradle of xt-domain-layer is:
rootProject.name = 'xt-domain-layer'
include 'xt-web'
Now from the root project graldetinker when I run \gradletinker>gradlew projects I do not getting the submodule xt-web listed
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'gradletinker'
\--- Project ':xt-domain-layer'
\gradletinker>gradlew -q :xt-domain-layer:projects
------------------------------------------------------------
Project :xt-domain-layer
------------------------------------------------------------
Project ':xt-domain-layer'
No sub-projects
Any idea where I am going wrong?
You use settings.gradle to add sub-projects to a gradle projects. The mechanism to add it is:
include 'subproject-folder-name'
or alternatively, if the subproject is located in some arbitrary location:
include ":subProj"
project(":subProj").projectDir = file("path/to/subproject")
In your case, add to xt-domain-layer settings.gradle:
include 'xt-web'
As per gradle docs. I only need a single settings.gradle file at the root level.
rootProject.name = 'gradletinker'
include 'xt-domain-layer:xt-web
So removed the settings.gradle files and added the following in settings.gradle at the root level.
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'gradletinker'
\--- Project ':xt-domain-layer'
\--- Project ':xt-domain-layer:xt-web'
Related
I have a 2 root projects in gradle one main root project1 from where I invoke gradle build and has settings.gradle which includes subprojects to build
Another root project2 where I have settings.gradle which includes subprojects to build
Rootproject1
build.gradle
settings.gradle
Rootproject2
build.gradle
settings.gradle
I want to inlcude Rootproject2 in my Rootproject1 settings.gradle file so that from Rootproject1 (gradle build) should build Rootproject1 as well as Rootproject2
include/inlcudeFlat -- it is relative to rootproject
There should be one settings.gradle which will be placed inside the primary root folder and you will need to write:
include ':Rootproject1',
':Rootproject2'
Then, in the build.gradle file of Rootproject1, you will need to write:
dependencies {
implementation project(path: ':Rootproject2')
}
[Updated on Jan 23, 2019] Something like following:
Root
|------ Rootproject1
|
|------ Rootproject2
|
|------ settings.gradle
I have two independent gradle projects that I also want to build from one main gradle project:
main-project
build.gradle
settings.gradle
--subproject-one
build.gradle
settings.gradle
--module-a
build.gradle
--subproject-two
build.gradle
settings.gradle
--module-b
build.gradle
My top settings.gradle includes all modules from the sub projects:
file('subproject-one').eachDir { dir ->
if(dir.list().contains("build.gradle")) {
include dir.name
project(":${dir.name}").projectDir = dir
}
}
file('subproject-two').eachDir { dir ->
if(dir.list().contains("build.gradle")) {
include dir.name
project(":${dir.name}").projectDir = dir
}
}
Now i have a dependency from module-b in subproject-two to module-a in subproject-one. I use a compile switch (useProjectDependencies) to include them as project dependencies when I build from the main project and as normal dependencies when i build from the subprojects:
if(useProjectDependencies){
compile project(':module-b')
} else {
//Client dependencies
compile "my.group.id:module-b
}
Via gradle I'm now able to build the main-project including the subproject and also each subproject on it's own.
When I open the main-project now via IntelliJ I see all the modules are recognized correctly and also the cross references to classes between the modules work correctly (refactoring interface between to components are working great).
When I now try to use the gradle integration from Intellij and click on assemble for the module-b then it incorrectly uses the build.gradle form and settings.gradle from subproject-two and doesn't use the project dependencies. It looks like IntelliJ or the gradle daemon searches for the first settings.gradle in a bottom up way from the module-b instead of using the one in the main-project.
When I build via terminal from the main-project folder all works correctly:
gradlew :module-b:assemble //correct *settings.gradle* and *build.gradle* is used
When I delete the settings.gradle and build.gradle from subproject-two then the build.gradle from the main-project is correctly used.
Is there a way to specify the settings.gradle and build.gradle that is used as part of the IntelliJ gradle integration?
Here's my project structure:
../project
/submodule1
/submodule2
/src
build.gradle
settings.gradle
Here's how I'm including the submodules using the settings.gradle file:
rootProject.name = 'rootProjectName'
include ':submodule1', ':submodule2'
Here's the properties I'm setting up sonarqube in the build.gradle file:
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.profile", "Sonar Profile"
property "sonar.projectName", rootProject.name
property "sonar.projectKey", "KEY${rootProject.name}"
}
}
And how I'm including the submodules in the root project:
dependencies {
..
compile project(":submodule1")
compile project(":submodule2")
}
But the soanrqube report is only showing results from analyzing the submodules, which ends up to be only ~100 lines of code when it should be much larger. I'm not sure what's wrong...
The support of modules having both source code and submodules was added in SonarQube 6.4:
https://jira.sonarsource.com/browse/SONAR-6724
In a gradle multi-module project, can the parent and sub-projects be siblings?
-parent
--build.gradle
--settings.gradle
-sub-project-1
--build.gradle
-sub-directory
--sub-module-2-1
---build.gradle
--sub-module-2-2
---build.gradle
Yes, it's possible to configure it this way, by declaring subprojects within settings.gradle as includeFlat instead of simple include. You can read about it here
But in that case, you have to run Gradle from the directory. where settings.gradle file is located, otherwise it won't find any subprojects.
Lets have this structure
I am in subproject1 how to write my settings.gradle file to include subproject1 and subproject2 as subprojects of the root Project. My settings.gradle file is in master directory?
I tried:
include 'root:subproject1', 'root:subproject2'
but nothing happened.
From Gradle doc:
If you execute Gradle from within a project that has no settings.gradle file, Gradle does the following:
It searches for a settings.gradle in a directory called master which has the same nesting level as the current dir.
If no settings.gradle is found, it searches the parent directories for the existence of a settings.gradle file.
If no settings.gradle file is found, the build is executed as a single project build.
If a settings.gradle file is found, Gradle checks if the current project is part of the multiproject hierarchy defined in the found settings.gradle file. If not, the build is executed as a single project build. Otherwise a multiproject build is executed.
includeFlat 'subproject1', 'subproject2'
includeFlat is a short form for include-ing the projects and then setting their projectDirs as appropriate for a flat directory layout.
For more information, see the "Multi-project builds" chapter in the Gradle User Guide, and the sample builds in the full Gradle distribution.
Good project structure.
settings.gradle of the master directory should have the following include statements to have subproject1, subproject2 as a multi-module project.
rootProject.name = 'app-name'
includeFlat 'subproject1'
includeFlat 'subproject2'
There is no need to have settings.gradle inside subproject1, subproject2 modules.
version.gradle and settings.gradle can be saved best under the master module only.
subproject1, subproject2 can have build.gradle with specific dependencies section wrt to their projects. Common dependencies can be stated under build.gradle of master.
It is nice to have "gradle" with wrapper folder under the master, so that the latest version of the Gradle can be downloaded to build multi-module sub-projects. ( e.g: gradlew )