• Stars
    star
    493
  • Rank 89,306 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

How do I idiomatically structure a large build with Gradle 7.2+?

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

Example

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

Alternative structuring options (on branches)

Discussions and alternative structuring options

More questions or points you would like to discuss? Please open an issue.

FAQ

More questions or points you would like to discuss? Please open an issue.

More Repositories

1

understanding-gradle

The Understanding Gradle video series introduces the concepts of the Gradle Build Tool one-by-one in short videos.
Java
256
star
2

gradle-project-setup-howto

How to structure a growing Gradle project with smart dependency management?
Java
139
star
3

gradle-plugins-howto

How to write Gradle plugins - answers to common questions and alternative implementation solutions
Java
129
star
4

gradle-demos

A collection of sample builds demonstrating how to do different things in Gradle
Java
51
star
5

gradle-module-metadata-maven-plugin

A Maven plugin to publish Gradle Module Metadata
Java
12
star
6

missing-metadata-guava

A Gradle plugin that provides additional metadata for Guava versions that were not published with Gradle Module Metadata.
Groovy
11
star
7

gradle-jpms-experiments

Kotlin
6
star
8

gradle-dependency-constraints

Kotlin
5
star
9

jjohannes

4
star
10

gradle-workshops

Java
4
star
11

gradle-training

Kotlin
3
star
12

what-if-gradle-metadata

What if... Gradle Module Metadata would have existed when your favorite JVM library was published
Kotlin
3
star
13

behind-the-magic-of-gradle-with-kotlin

2
star
14

java-module-system

Slides and links about Java Module System development with Gradle
Java
2
star
15

playdate-sprite-match

Kotlin
2
star
16

missing-metadata-jackson

A Gradle plugin that adds additional metadata to 2.6.7+ releases of the https://github.com/FasterXML/jackson libraries.
Java
1
star
17

java-magazin-gradle-7

Project used in the Java Magazin article about Gradle 7
Kotlin
1
star
18

gradle-version-attribute

Kotlin
1
star
19

gradle-tooling-api-as-module

Kotlin
1
star
20

dependency-update-playground

Java
1
star
21

java-module-read-all-unnamed

Java
1
star
22

java-magazin-gradle-6

Project used in the Java Magazin article about Gradle 6
Kotlin
1
star
23

plain-c

Java
1
star