• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

jjohannes/idiomatic-gradle: How do I idiomatically structure a large build with ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

jjohannes/idiomatic-gradle

开源软件地址(OpenSource Url):

https://github.com/jjohannes/idiomatic-gradle

开源编程语言(OpenSource Language):

Kotlin 72.1%

开源软件介绍(OpenSource Introduction):

Example of how to idiomatically structure a large build with Gradle 7.2+

For a better understanding of the concepts used in this example, check out Understanding Gradle.

In addition to this, check How to set up a larger Gradle project.

Example

There is now documentation and another sample on this topic in the Gradle User Manual.

This example is a software product called Idiomatic Gradle (IG).

To build the example, clone this repository and run the following for more information:

  • ./gradlew :tasks
  • ./gradlew :projects

This example consists of:

Production code

Inside the 'product' folder, there are three components/builds:

  • product/ig-server: A server providing some services
  • product/ig-api: A client API Jar that clients (e.g. Android Apps) can integrate directly
  • product/ig-common: Some common code used by both Server and API Jar

For the sake of the sample each of these folders only contain one subproject. In a real-world application, this can be structured into many, many more Gradle subprojects.

Packaging and Publishing

Both the server and the client API Jar require some special packaging to be published/distributed. Hence, this is configured in a separate component/build only responsible for aggregating build results:

  • aggregation/package-server: Package the complete server and its dependencies into one fat jar that can run without other dependencies
  • aggregation/publish-api: Package the client into one Jar that is published to a Maven repository

Testing

Each project contains unit tests using Gradle's default setup for Java projects with the src/test/java folder. Furthermore, some projects contain end2end tests testing with the real (packaged) server and the real client API Jar. For this, the packaging/publishing projects provide their results in the build for other subprojects to consume.

Idiomatic Build Logic Structure

The build contains some standard configuration for Java compilation and testing. It contains more involved configuration code to configure the packaging/publishing and the end2end test setup. There are multiple ways to do all this in Gradle today. This sample employs the following good patterns which result in a good build structure (easy to maintain and fast for Gradle to execute) as described here.

With this, the following outdated practices are avoided:

  • No direct dependencies between tasks declared (except for extending lifecycle tasks like assemble or check)
  • No direct dependencies between tasks from different subprojects are declared
  • No cross-project configuration (subproject / allprojects) is performed
  • Each build script of a subproject is simpler to read as all relationships to other projects are expressed in terms of dependencies
  • ...



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap