Gradle Multi-Project Build and Encapsulation - gradle

I'm using gradle as build engine for multiple projects. I have the following dependency between the projects:
- MobileApp
|
+-- CordovaPlugin
|
+--Docs
|
+--NativeiOSImpl
| |
| +--Docs
+--NativeAndroidImpl
|
+--Docs
Each of the projects is a project on it own so each project has it own build.gradle file and settings.gradle.
My problem is that I have to repeat the settings.gradle in each level.
Am I missing something or there is no encapulation of a project in gradle?

Related

Maven Archetype With Custom File Structure

I am trying to use Maven Archetypes to create a basic directory structure for a new project that is just a parent to several child projects. The structure inside archetype-resources looks like this:
root
|--- pom.xml
|--- subproject1
| \--- foo.xml
|
\--- subproject2
\--- bar.xml
Instead of generating this structure, I get the following error:
Template 'subproject1/foo.xml' not in directory 'src/main/java'
Is there a way to tell Maven to not assume the archetype is generating a Maven Java project?

Share dependency versions between Maven (pom.xml) and Gradle (build.gradle)

I have projects built by Maven and Gradle. Is there a way to define dependency versions in a text file, e.g.:
.
|-- dep-versions.properties
|
|-- proj-by-gradle
| |-- build.gradle
| `-- settings.gradle
|
`-- proj-by-maven
`-- pom.xml
Is there an easy way to specify in dep-versions.properties, something like:
com.google.guava:guava = 26.0-jre
org.apache.commons:commons-pool2 = 2.5.0
And then use these versions in both the pom.xml and build.gradle?
You can create a BOM pom (Bill of materials) and use it in both builds. Support for importing maven BOM files was added to Gradle in version 4.6: https://docs.gradle.org/4.6/release-notes.html#bom-import

Gradle multiproject doesn't add projects to classpath

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...

Gradle - build subprojects subprojects

Assume I have a Gradle project that looks like
RootProject
|-- SubProject1
| |- SubProject1A
| | `- build.gradle
| `- SubProject1B
| `- build.gradle
|-- SubProject2
| |- SubProject2A
| | `- build.gradle
| `- SubProject2B
| `- build.gradle
|- gradle.build
`- settings.gradle
Is it possible to build a subprojects all subprojects? I want to run
gradle :SubProject1:build
But it doesn't build the subprojects SubProject1A and SubProject1A
My settings.gradle looks like
include ":SubProject1:SubProject1A"
include ":SubProject1:SubProject1B"
include ":SubProject2:SubProject2A"
include ":SubProject2:SubProject2A"
How can I build a subprojects all subprojects?
I might be wrong, but I believe you also need a build.gradle in SubProject1 and SubProject2
Edit:
I found the solution.
Create a build.gradle in SubProject1 and SubProject2 and add a task dependency to SubProject1A and SubProject1B etc like this:
build.dependsOn ':SubProject1:SubProject1A:build', ':SubProject1:SubProject1B:build'
You can then run :SubProject1:build and it will also execute :SubProject1:SubProject1A:build and :SubProject1:SubProject1B:build

Want to build multimodule pom which builds 2 ear from same project in maven

I have one main PTC Project inside which I have different modules(sub projects)
PTC
|
+-- pom.xml
|
+-- PrismaTestClientConfig
|
+-- PrismaTestEarM
| |
| \-- pom.xml
|
+-- PrismaTestClientHTMLGeneration
| |
| \-- pom.xml
|
+-- PrismaTestClientWeb
| |
| \-- pom.xml
|
+-- PrismaTestCommon
\
<modules>
<module>PrismaTestCommon</module>
<module>PrismaTestClientHTMLGeneration</module>
<module>PrismaTestClientWeb</module>
<module>PrismaTestClientEarM</module>
</modules>
So I have one common pom.xml of PTC which contains above dependency of module:
The above thing builds ptc.ear
Now I want to add 2 modules BTCHTMLGeneration on BTCEarM and use PTCCommon and PTCWeb from PTC and build btc.ear. Also when i want to build ptc.ear it takes above 4 module and when i want to build btc.ear , it shoud take common 2 module from PTC and 2 new module from BTC
How can I achieve this...Please help
Simply create two separate modules btc.ear (better name them btc-ear or ptc-ear) and add the appropriate dependencies to the ear modules. Take a deep look into the maven-ear-plugin documentation.

Resources