# Using composite builds in a hierarchical multirepo project
This sample demonstrates how composite builds can be used to develop a hierarchical project that is composed from different Git repositories. Instead of Gradle subprojects in a multiproject build, this example uses separate Gradle builds included into a composite.
In addition to the benefits of a multirepo architecture, using a Gradle composite build in this way allows a developer to easily choose which modules to develop as source dependencies and which to integrate via a binary repository.
### Running `multirepo-app` with dependencies from included builds
In the first instance, all of the required dependencies are present as builds in the `modules` directory. In a real-world example, these could well be clones of different Git repositories.
In order to avoid hard-coding the included builds to load, the `settings.gradle` file in `multirepo-app` loads each of these builds dynamically:
```
file('modules').listFiles().each { File moduleBuild ->
includeBuild moduleBuild
}
```
When the `multirepo-app` build is executed, these module builds are used to generate the dependent artifacts:
```
gradle run
```
And the 'dependencies' report shows the dependency substitution in action:
```
gradle dependencies --configuration compile
```
>>>
```
compile - Dependencies for source set 'main'.
+--- org.sample:number-utils:1.0 -> project :number-utils
\--- org.sample:string-utils:1.0 -> project :string-utils
\--- org.apache.commons:commons-lang3:3.4
```
### Switching to use binary dependency
As long as the modules are available in a binary repository, the `multirepo-app` build will continue to work even if you don't have some modules available locally. In this case Gradle will use a binary dependency downloaded from a repository instead.
#### Preparing the binary repository
To demonstrate this functionality, we first need to publish each module to a binary repository. In this case we use a local file repository for this purpose:
```
gradle :publishDeps
```
The `publishDeps` creates and uploads the artifacts for each included build. It is defined in `multirepo-app` as follows:
```
task publishDeps {
dependsOn gradle.includedBuilds*.task(':uploadArchives')
}
```
#### Removing the local module source
With module artifacts available in a repository, we can now remove the module sources from the build. Since the composite is configured to automatically load available modules, this is as easy as deleting one or more module directories.
```
rm -r modules/string-utils
gradle run
```
Note that the `number-utils` dependency is still satisfied by the included build, while the `string-utils` dependency is now resolved from the repository.
The 'dependencies' report shows the dependency substitution in action:
```
gradle dependencies --configuration compile
```
>>>
```
compile - Dependencies for source set 'main'.
+--- org.sample:number-utils:1.0 -> project :number-utils
\--- org.sample:string-utils:1.0
\--- org.apache.commons:commons-lang3:3.4
```
### Including an external library as a submodule
The power of this configuration can be demonstrated by adding the external 'commons-lang' build directly to the composite.
```
git clone http://git-wip-us.apache.org/repos/asf/commons-lang.git modules/commons-lang --branch master --depth 1
gradle --project-dir modules/commons-lang --no-search-upward init
gradle run
```
You can see the external transitive dependency `commons-lang` being replaced with the local project dependency by running:
```
gradle dependencies --configuration compile
```
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
打造终极MVP+Retrofit2+okhttp3+Rxjava2网络请求,开发实用,简约 (12441个子文件)
libgtest.a 911KB
libgtest.a 782KB
libcunit.a 95KB
libcunit.a 79KB
appcompat-v7-26.1.0.aar 981KB
appcompat-v7-27.1.1.aar 977KB
support-compat-26.1.0.aar 621KB
support-compat-27.1.1.aar 543KB
espresso-core-3.0.2.aar 542KB
support-media-compat-26.1.0.aar 305KB
support-core-ui-27.1.1.aar 265KB
support-core-ui-26.1.0.aar 228KB
support-fragment-27.1.1.aar 165KB
runner-1.0.2.aar 162KB
support-fragment-26.1.0.aar 161KB
support-core-utils-27.1.1.aar 94KB
support-core-utils-26.1.0.aar 85KB
constraint-layout-1.1.3.aar 63KB
monitor-1.0.2.aar 57KB
animated-vector-drawable-26.1.0.aar 34KB
animated-vector-drawable-27.1.1.aar 34KB
support-vector-drawable-26.1.0.aar 31KB
support-vector-drawable-27.1.1.aar 30KB
MultiWaveHeader-1.0.0-alpha-1.aar 22KB
logger-2.2.0.aar 20KB
runtime-1.1.0.aar 10KB
runtime-1.0.0.aar 9KB
livedata-core-1.1.0.aar 9KB
rxandroid-2.0.2.aar 8KB
viewmodel-1.1.0.aar 7KB
runtime-1.1.0.aar 6KB
espresso-idling-resource-3.0.2.aar 5KB
support-v4-26.1.0.aar 3KB
MediaSessionCompat.aidl 787B
ParcelableVolumeInfo.aidl 689B
PlaybackStateCompat.aidl 688B
MediaDescriptionCompat.aidl 683B
MediaMetadataCompat.aidl 680B
ResultReceiver.aidl 675B
ResultReceiver.aidl 675B
RatingCompat.aidl 673B
org.codehaus.groovy.transform.ASTTransformation 34B
gradlew.bat 2KB
gradle.bat 2KB
artifact-at-url.bin 212KB
results.bin 51KB
artifact-at-repository.bin 44KB
fileHashes.bin 28KB
module-artifacts.bin 26KB
module-metadata.bin 24KB
resourceHashesCache.bin 21KB
descriptor.bin 915B
descriptor.bin 829B
descriptor.bin 801B
descriptor.bin 623B
descriptor.bin 605B
descriptor.bin 587B
descriptor.bin 540B
descriptor.bin 537B
descriptor.bin 533B
descriptor.bin 523B
descriptor.bin 514B
descriptor.bin 494B
descriptor.bin 493B
descriptor.bin 490B
descriptor.bin 484B
descriptor.bin 436B
descriptor.bin 411B
descriptor.bin 408B
descriptor.bin 382B
descriptor.bin 376B
registry.bin 365B
descriptor.bin 352B
descriptor.bin 346B
descriptor.bin 346B
descriptor.bin 346B
descriptor.bin 346B
descriptor.bin 343B
descriptor.bin 342B
descriptor.bin 339B
descriptor.bin 337B
descriptor.bin 317B
descriptor.bin 312B
descriptor.bin 299B
descriptor.bin 297B
descriptor.bin 294B
descriptor.bin 287B
descriptor.bin 279B
descriptor.bin 276B
descriptor.bin 275B
descriptor.bin 261B
descriptor.bin 258B
descriptor.bin 258B
descriptor.bin 253B
descriptor.bin 253B
descriptor.bin 236B
descriptor.bin 236B
descriptor.bin 236B
descriptor.bin 235B
descriptor.bin 224B
共 12441 条
- 1
- 2
- 3
- 4
- 5
- 6
- 125
资源评论
打酱油的日光灯
- 粉丝: 36
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功