An open API service indexing awesome lists of open source software.

https://github.com/autonomousapps/composite-build-gradle-lifecycle

A demonstration of the only possible (?) way to use the gradle.lifecycle hook from a convention plugin provided by an included build
https://github.com/autonomousapps/composite-build-gradle-lifecycle

Last synced: about 1 month ago
JSON representation

A demonstration of the only possible (?) way to use the gradle.lifecycle hook from a convention plugin provided by an included build

Awesome Lists containing this project

README

          

# Composite builds and the `gradle.lifecycle` API

https://docs.gradle.org/current/userguide/isolated_projects.html#new_gradle_lifecycle_callbacks

https://github.com/gradle/gradle/issues/36461

It doesn't seem possible to reference a plugin provided by an included build (`build-logic`) in the main build's
`gradle.lifecycle.beforeProject` callback. I've tried with both of the following:

```kotlin
// main build's settings.gradle.kts
// (1)
pluginManagement {
includeBuild("build-logic")
}

// (2)
includeBuild("build-logic")

// (3)
gradle.lifecycle.beforeProject {
pluginManager.apply("buildlogic.my-cool-convention")
}
```

No combination of (1) and (2) make (3) possible. The build-logic plugin simply isn't visible on the classpath, for
inscrutable reasons. Not trying to be cute with that; as far as I know, Gradle's class loading is undocumented, although
I made a partial attempt with the series beginning with
[Build, compile, run: A crash course in classpaths](https://dev.to/autonomousapps/build-compile-run-a-crash-course-in-classpaths-f4g).

**However, the following does work:**

```kotlin
// main build's settings.gradle.kts
pluginManagement {
includeBuild("build-logic")
}

plugins {
id("buildlogic.my-cool-settings-convention")
}
```

and

```kotlin
// build-logic/src/main/kotlin/buildlogic.my-cool-settings-convention.settings.gradle.kts
gradle.lifecycle.beforeProject {
pluginManager.apply("buildlogic.my-cool-convention")
}
```