GithubHelp home page GithubHelp logo

cxwudi / modern-gradle-template Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 2.27 MB

A crazy learning outcome from https://www.udemy.com/course/modern-gradle-fundamentals/

License: MIT License

Kotlin 92.15% Java 7.85%
gradle-template gradle-template-project gradle gradle-kotlin-dsl

modern-gradle-template's Introduction

Good News: I made a simplified version of this template, check it out

modern-gradle-template

I learn Gradle because I want a simplified syntax to describe a multi-module project, so I payed and learned from Udemy

But I end up with this crazy setup that is 10x more complicated than my current maven multi-module project setup ๐Ÿ˜‚

Definitely overkilled for small, personal, or school projects...

How crazy ๐Ÿ˜ฒ is this template

See how I structured my precompiled script plugins

image

Also, each module is an independent submodule in the gradle/plugins build source project, and each module in the same layer will never depend on each other.

This is explicitly designed to boost build performance from gradle parallel execution.

performance boost

I want to use this template

Good News: I made a simplified version of this template, check it out

Thanks for considering my template ๐Ÿ™‚, just do the following things, and you are good to go:

  1. Delete these sample submodules begin with sample-, and update the logic of including submodules in the root settings.gradle.kts
  2. Modify the project name rootProject.name in settings.gradle.kts to your own project name.
  3. Globally change the group name poc.cx.glp to your own group name. The group name poc.cx.glp is defined in dev-version-constraints module and is referred in the root plugin and the lib mixin plugin.
  4. Delete everything in mixin plugins folder and convention plugins folder, and delete everything in the version catalog, and delete everything in the constraints block in the dev-version-constraints platform
    • Tips: you can choose to not delete some stuff if you find them useful
  5. Add your own mixin plugins and convention plugins, and don't forget to archive centralized version management by adding your own libraries into the version catalog.
    • Tip 1: if you want to use version catalog in the dependencies block in precompiled script plugins (mixin or convention plugins), put them in the constraints block in the dev-version-constraints platform. Then in precompiled script plugins, declare the library dependency without the version (e.g. implementation("org.springframework.boot:spring-boot-starter")). This works for Maven bom and Gradle platform as well.
    • Tip 2: if you want to use version catalog in the plugins block in precompiled script plugins (mixin or convention plugins), you instead let the build.gradle.kts (is also the one with kotlin-dsl applied) that build the precompiled script plugin applies the version catalog. Then in precompiled script plugins, declare the library dependency without the version ((e.g. id("org.springframework.boot"))

This template also contains two ways for updating library dependencies automatically, either by using renovate bot (recommended as it is the only tool that support Gradle version catalog so far), or running Gradle tasks defined in the root build.gradle.kts

modern-gradle-template's People

Contributors

cxwudi avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

modern-gradle-template's Issues

We now needs `gradle/plugins-plugins`...

We simply just want to apply the version catalog updater plugin into the root build.gradle.kts file in gradle/plugins which itself is a Gradle project defined all our convention plugins

Some refactor

  1. move kotest-spring-extension to kotest-jvm, done by doing a check. So spring-boot-kotlin-mixin would not deal with kotest
  2. merge spring-boot-mockk-mixin into spring-boot-kotlin-mixin, and create a new extension for choosing mockk vs mockito, default to mockk

Platform first or version catalog first for centralized version management

Currently, our centralized version management is done by Gradle platform, inspired from this video. And it also uses version catalog like shown in Gradle doc (we do that mainly just for learning purposes)

This makes adding/removing new dependencies very tedious as it requires modifying 3 places, the catelog, the platform, and finally the build script that uses the dep. It is fine for a precompiled script plugin (due to limitation in gradle/gradle#15383, but I don't like that hack). But for normal main build script, it is very annoying.

By switching version catalog first approach, only the dep-version-constarint platform will be preserved and used by the precompile script plugins, other platforms will be deleted and all gradle/plugins & gradle/settings will use version catalog.

Another choice is just delete version catalog and use platforms only

About achieving maximum parallelism in plugins builds

#1 was the success attempt to refactor convention plugins from inheritance way of thinking to composite way of thinking

A further improvement is to achieve maximum parallelism where each convention plugin is one submodule in gradles/plugins,
(make sure org.gradle.parallel=true is in gradle.properties) but then this introduces very high management overhead.

FYI, includeBuild("gradles/plugins") from root settings.gradle.kts will force each module in gradles/plugins to be built as :jar before building the main build, but with caching, most of them should be UP-TO-DATE. Only modules that have changes AND modules that depends on these changed modules will be recompiled, so we want to eliminate the number of recompiled convention plugins but putting each convention plugin to its own submodule in gradles/plugins

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Location: renovate.json
Error type: Invalid JSON (parsing failed)
Message: Syntax error: expecting end of expression or separator near } "pack

Refactor precompiled script plugins folder structure in `/gradle/plugins`

The current way of structuring is not quite good, because everything is done in 'inheritence', instead of gradle's recommended 'composition'.

E.g. The my-kotlin-jvm-base plugin is the example where it needs to exclude lombok plugin that was added in my-java-base.

What we should do instead is to create something like my-lombok-trait plugin that simply just add the Lombok. Then my-java-app and my-java-lib should add this plugin, but not the my-kotlin-* plugins

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

docker-compose
docker/docker-compose.gradle-test.yml
github-actions
.github/workflows/gradle.yml
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/gradle-build-action v3
  • actions/checkout v4
  • actions/setup-java v4
  • gradle/gradle-build-action v3
gradle
gradle.properties
settings.gradle.kts
build.gradle.kts
gradle/libs.versions.toml
  • org.springframework.boot:spring-boot-dependencies 3.3.2
  • io.kotest:kotest-bom 5.9.1
  • org.jetbrains.kotlinx:kotlinx-coroutines-bom 1.8.1
  • org.jetbrains.kotlin:kotlin-gradle-plugin 2.0.10
  • org.jetbrains.kotlin:kotlin-allopen 2.0.10
  • io.freefair.lombok:io.freefair.lombok.gradle.plugin 8.7.1
  • org.springframework.boot:spring-boot-gradle-plugin 3.3.2
  • com.gradle.develocity:com.gradle.develocity.gradle.plugin 3.17.6
  • org.gradle.toolchains:foojay-resolver 0.8.0
  • com.github.CXwudi:kotlin-jvm-inline-logging 1.0.1
  • io.kotest.extensions:kotest-extensions-spring 1.3.0
  • org.mockito.kotlin:mockito-kotlin 5.4.0
  • io.mockk:mockk 1.13.12
  • com.ninja-squad:springmockk 4.0.2
  • org.graalvm.buildtools.native 0.10.2
  • org.jetbrains.kotlin.jvm 2.0.10
  • com.github.ben-manes.versions 0.51.0
  • nl.littlerobots.version-catalog-update 0.8.4
gradle/platform/settings.gradle.kts
gradle/platform/dev-version-constraints/build.gradle.kts
gradle/plugins/settings.gradle.kts
gradle/plugins/convention/java-app/build.gradle.kts
gradle/plugins/convention/java-app/src/main/kotlin/my.java-app.gradle.kts
gradle/plugins/convention/java-lib/build.gradle.kts
gradle/plugins/convention/java-lib/src/main/kotlin/my.java-lib.gradle.kts
gradle/plugins/convention/kotlin-app/build.gradle.kts
gradle/plugins/convention/kotlin-app/src/main/kotlin/my.kotlin-jvm-app.gradle.kts
gradle/plugins/convention/kotlin-lib/build.gradle.kts
gradle/plugins/convention/kotlin-lib/src/main/kotlin/my.kotlin-jvm-lib.gradle.kts
gradle/plugins/convention/kotlin-spring-app/build.gradle.kts
gradle/plugins/convention/kotlin-spring-app/src/main/kotlin/my.kotlin-spring-app.gradle.kts
gradle/plugins/convention/kotlin-spring-lib/build.gradle.kts
gradle/plugins/convention/kotlin-spring-lib/src/main/kotlin/my.kotlin-spring-lib.gradle.kts
gradle/plugins/convention/spring-app/build.gradle.kts
gradle/plugins/convention/spring-app/src/main/kotlin/my.spring-app.gradle.kts
gradle/plugins/convention/spring-lib/build.gradle.kts
gradle/plugins/convention/spring-lib/src/main/kotlin/my.spring-lib.gradle.kts
gradle/plugins/mixin/app/build.gradle.kts
gradle/plugins/mixin/app/src/main/kotlin/my/mixin/app.gradle.kts
gradle/plugins/mixin/junit5/build.gradle.kts
gradle/plugins/mixin/junit5/src/main/kotlin/my/mixin/junit5.gradle.kts
gradle/plugins/mixin/kotest-jvm/build.gradle.kts
gradle/plugins/mixin/kotest-jvm/src/main/kotlin/my/mixin/kotest-jvm.gradle.kts
gradle/plugins/mixin/kotlin-jvm/build.gradle.kts
gradle/plugins/mixin/kotlin-jvm/src/main/kotlin/my/mixin/kotlin-jvm.gradle.kts
gradle/plugins/mixin/lib/build.gradle.kts
gradle/plugins/mixin/lib/src/main/kotlin/my/mixin/lib.gradle.kts
gradle/plugins/mixin/lombok/build.gradle.kts
gradle/plugins/mixin/lombok/src/main/kotlin/my/mixin/lombok.gradle.kts
gradle/plugins/mixin/spring-boot-app/build.gradle.kts
gradle/plugins/mixin/spring-boot-app/src/main/kotlin/my/mixin/spring-boot-app.gradle.kts
gradle/plugins/mixin/spring-boot-common/build.gradle.kts
gradle/plugins/mixin/spring-boot-common/src/main/kotlin/my/mixin/spring-boot-common.gradle.kts
gradle/plugins/mixin/spring-boot-kotlin/build.gradle.kts
gradle/plugins/mixin/spring-boot-kotlin/src/main/kotlin/my/mixin/spring-boot-kotlin.gradle.kts
gradle/plugins/root/build.gradle.kts
gradle/plugins/root/src/main/kotlin/my/root/jvm.gradle.kts
gradle/settings/settings.gradle.kts
gradle/settings/root-settings-plugins/build.gradle.kts
gradle/settings/root-settings-plugins/src/main/kotlin/my.root-settings-plugins.settings.gradle.kts
sample-java-lib/build.gradle.kts
sample-kotlin-app/build.gradle.kts
sample-kotlin-spring-app/build.gradle.kts
sample-kotlin-spring-lib/build.gradle.kts
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.10

  • Check this box to trigger a request for Renovate to run again on this repository

Namespace refactoring

So far our precompiled script plugins in gradle/plugins are all stored in root of src/main/kotlin, and everyone has the name like my.xxx-mixin/conversion/root

As we grow and develop more stuff, it is hard to manage them in the root directory.

To be consisted with the gradle/plugins directory structure, we will move these plugins into src/main/kotlin/my/<type> directory. for example:

  1. src/main/kotlin/my.jvm-root.gradle.build.kts -> src/main/kotlin/my/root/jvm.gradle.build.kts
  2. src/main/kotlin/my.spring-boot-mxin.gradle.build.kts -> src/main/kotlin/my/mixin/spring-boot.gradle.build.kts

and etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.