Skip to content

Commit

Permalink
Document publish task stubs in included builds
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed Jul 23, 2024
1 parent 6dcc984 commit 80d078c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ plugins {
}

rootProjectConvention {
// Add `publishAll` and `publish` tasks that delegate to the subprojects and included builds.
registerPublishTasks.set(true)
}
21 changes: 21 additions & 0 deletions docs/content/conventions/rootproject.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ rootProjectConvention {
registerStubPublishTasks.set(false)
}
```


## Publish Tasks
By default, the Root Project convention plugin only creates lifecycle tasks (`build`, `assemble`, `clean`, `check`, and their corresponding versions with the `All` suffix), but no tasks for publishing. The reasoning is that not all subprojects and included builds will be configured to be published, and as such, delegating `publish` to these included builds can cause errors. However, if you _do_ want root-level `publish` and `publishToMavenLocal` tasks (and `publishAll` and `publishAllToMavenLocal`), then you can achieve this by setting `registerPublishTasks` to `true` in the root project:

```kotlin title="build.gradle.kts"
rootProjectConvention {
registerPublishTasks.set(true)
}
```

!!! warning ""
This assumes that all included builds have `publish` and `publishToMavenLocal` tasks. This is generally not the case, as not all included builds may have the `maven-publish` plugin applied. In contrast, for subprojects this is already handled correctly by this plugin.

For included builds that will not be published, we have to add _stub_ `publish` and `publishToMavenLocal` tasks. These tasks will do nothing, but will prevent errors when the root project tries to delegate these tasks to the included builds. To add these stub tasks, set `registerStubPublishTasks` to `true` in the included build's root project:

```kotlin title="build.gradle.kts"
rootProjectConvention {
registerStubPublishTasks.set(true)
}
```
2 changes: 2 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ allprojects {


rootProjectConvention {
// Just register some stub `publish` and `publishToMavenLocal` tasks,
// so we can call `publish` on all included builds from the root without issues.
registerStubPublishTasks.set(true)
}
2 changes: 0 additions & 2 deletions example/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.metaborg.convention.MavenPublishConventionExtension

rootProject.name = "example-project"

pluginManagement {
Expand Down

0 comments on commit 80d078c

Please sign in to comment.