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
Related
Is there a way to tell Gradle
"Hey, there's a build.gradle.kts in the directory some/subdir, but please act like it's not there and don't try to mess with it at all"?
I have to keep a non-Android Kotlin project in an Android repository with a build.gradle.kts-file in the repository root for ... reasons ... and it keeps breaking my build due to plugin version conflicts.
The hierarchy layout is as follows:
|-- build.gradle.kts
|-- settings.gradle.kts
|-- src/
|-- android_project_a/
|-- build.gradle.kts
|-- android_project_b/
|-- build.gradle.kts
|-- kotlin_project/
|-- build.gradle.kts // This is what I need to exclude
If you are using command line to build, You can execute subdir as following
gradle build -x kotlin_project:build
But this is not a nice way to have it done, I wanted to check your build.gradle and setting.gradle, As you can change that once and for all, If you change the sub-projects and implementation of your sub-projects.
This kotlin_project should be a part of your setting.gradle as its being build automatically when you trigger root dir build.
You can exclude it if you want, But you have to remove it as well from dependencies at your build.gradle
I have some projects that depend on others. I also have a project that depends on two projects that each one depends on the same project. Something like this:
-Project A
* Project 1
** Project C
* Project 2
** Project C
And the structure of the workspace is like this:
-ProjectA
-ProjectC
-Project1
-Project2
All the projects are at the same level.
So in the settings.gradle in my Project A I have:
include ':Project1',':Project1:ProjectC',[...]
project(':Project1') = new File('../Project1')
project(':Project2') = new File('../Project2')
project(':Project1:ProjectC') = new File('../ProjectC')
project(':Project2:ProjectC') = new File('../ProjectC')
And in the build.gradle I do:
dependencies{ compile project('Project1'),project('Project2')
The problem is that it is not correctly added to the classpath. I think since both Project1 and Project2 depends on ProjectC it is overwritten somehow. Any ideas?
Thanks.
EDIT
Here is the tree of dependencies:
Root project 'ProjectA'
+--- Project ':ProjectB'
| \--- Project ':ProjectB:Project1'
| +--- Project ':ProjectB:Project1:Project2'
| \--- Project ':ProjectB:Project1:Project3'
\--- Project ':ProjectC'
\--- Project ':ProjectC:Project1'
+--- Project ':ProjectC:Project1:Project2'
\--- Project ':ProjectC:Project1:Project3'
For a workspace that looks like this:
rootFolder
|
|- build.gradle
|- settings.gradle
|
|- ProjectA
| |-build.gradle
|
|- Project1
| |-build.gradle
|
|- Project2
| |-build.gradle
|
|- ProjectC
|-build.gradle
Your settings.gradle should look like this (irrespective of dependency relationships of the sub projects):
include ':ProjectA',':Project1',':Project2',':ProjectC',
You're just telling the root project that there are 4 subprojects and where they are located. That's it.
Now the dependency relationships are handled inside each subproject's build.gradle files. For a dependency relationship that looks like this:
ProjectA
|-Project1
| |-ProjectC
|
|-Project2
|-ProjectC
ProjectA's build.gradle:
dependencies{
compile project(':Project1')
compile project(':Project2')
}
Project1's build.gradle:
dependencies{
compile project(':ProjectC')
}
Project2's build.gradle:
dependencies{
compile project(':ProjectC')
}
What I finally did is change in the classpath the paths that where wrong like this:
build.gradle
eclipse{
classpath{
file{
whenMerged { classpath ->
classpath.entries.find { entry ->
entry.kind == 'src' && entry.path.contains('ProjectC')
}.each{ entry ->
entry.path=file("/ProjectC")
}
}
}
}
}
And it works fine. I still don't know why gradle doesn't make the classpath correctly...
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'
i have a project layout like
sample/
A/
src/
main/
java/
A.java
res/
A.jpg
B/
src/
main/
java/
B.java
res/
B.jpg
build.gradle
settings.gradle
how to create two separate jar files(A.jar/B.jar)
A.jar includes A.java, A.jpg
B.jar includes B.java, B.jpg
Here you can find a sample project. Basically all configuration is put in build.gradle and settings.gradle files:
build.gradle
subprojects {
apply plugin: 'java'
}
settings.gradle
include 'A', 'B'
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 )