Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: Rewrite Build Lifecycle documentation in a consistent docs voice #23577

Merged
merged 26 commits into from Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b6cfefe
Rewrite Build Lifecycle documentation in a consistent docs voice
Oct 19, 2022
d7abd5c
Fix links broken during refactor
Oct 21, 2022
ffc3273
Merge branch 'release7x' into frauboes/docs/build-lifecycle
Jan 19, 2023
7f59776
Clarify that plugins also configure the dependency graph.
nathan-contino Oct 20, 2022
039e5e6
Tighten up description of execution phase
nathan-contino Oct 20, 2022
e13524e
Add included builds mention to build lifecycle explanation
nathan-contino Oct 20, 2022
80542c3
Add included builds to another section of the build lifecycle doc
nathan-contino Oct 20, 2022
b1b79bb
Add composite builds mention in lifecycle docs
nathan-contino Oct 20, 2022
8ef6057
Change create to register, clarify configuration actions
nathan-contino Oct 20, 2022
a769dfe
Replace Project.afterEvaluate with gradle.afterProject
nathan-contino Oct 20, 2022
ac93d0d
Make it clearer that you should always define a settings file
nathan-contino Oct 21, 2022
3eb95d6
Clarify settings file evaluation order
nathan-contino Oct 21, 2022
b4b6c18
Included Kotlin and Groovy DSL settings file variants
nathan-contino Oct 21, 2022
31daead
Link to settings file documentation on first occurrence
nathan-contino Oct 21, 2022
d568062
Clarify that task graph applies to requested tasks only
nathan-contino Oct 21, 2022
1caab0d
Inclusivity for Kotlin AND Groovy DSLs
nathan-contino Oct 21, 2022
2a393c9
Include Kotlin and Groovy DSL
nathan-contino Oct 21, 2022
e77611d
Clarify that task execution graph only includes requested tasks
nathan-contino Oct 21, 2022
fb06945
Remove allproject antipattern and eliminate now-redundant afterProjec…
Oct 21, 2022
4e3fe3f
Update subprojects/docs/src/docs/userguide/authoring-builds/build_lif…
nathan-contino Oct 24, 2022
1a661ef
Switch example to ExtraProperties
Oct 25, 2022
99e3bf9
Make project closure arg explicit
Oct 26, 2022
e562276
Remove explicit project arg from kotlin
Oct 26, 2022
9404ac1
Fix type inference failure
Oct 26, 2022
1e69399
Update subprojects/docs/src/docs/userguide/authoring-builds/build_lif…
nathan-contino Oct 24, 2022
365c6a2
Merge branch 'release7x' into frauboes/docs/build-lifecycle
Jan 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion subprojects/docs/src/docs/userguide/api/kotlin_dsl.adoc
Expand Up @@ -158,7 +158,7 @@ Groovy DSL script files use the `.gradle` file name extension.
Kotlin DSL script files use the `.gradle.kts` file name extension.
====

To activate the Kotlin DSL, simply use the `.gradle.kts` extension for your build scripts in place of `.gradle`. That also applies to the <<build_lifecycle#sec:settings_file,settings file>> — for example `settings.gradle.kts` — and <<init_scripts#init_scripts,initialization scripts>>.
To activate the Kotlin DSL, simply use the `.gradle.kts` extension for your build scripts in place of `.gradle`. That also applies to the <<organizing_gradle_projects#sec:settings_file,settings file>> — for example `settings.gradle.kts` — and <<init_scripts#init_scripts,initialization scripts>>.

Note that you can mix Groovy DSL build scripts with Kotlin DSL ones, i.e. a Kotlin DSL build script can apply a Groovy DSL one and each project in a multi-project build can use either one.

Expand Down

Large diffs are not rendered by default.

Expand Up @@ -89,17 +89,21 @@ While those conventions can be reconfigured, it makes it harder to build script
Try to stick to the default conventions as much as possible except if you need to adapt to the layout of a legacy project.
Refer to the reference page of the relevant plugin to learn about its default conventions.

[[sec:settings_file]]
== Always define a settings file

Gradle tries to locate a `settings.gradle` (Groovy DSL) or a `settings.gradle.kts` (Kotlin DSL) file with every invocation of the build.
For that purpose, the runtime walks the hierarchy of the directory tree up to the root directory.
The algorithm stops searching as soon as it finds the settings file.

Always add a `settings.gradle` to the root directory of your build to avoid the initial performance impact.
This recommendation applies to single project builds as well as multi-project builds.
The file can either be empty or define the desired name of the project.

A typical Gradle project with a settings file look as such:
A multi-project build must have a `settings.gradle(.kts)` file in the root project of the multi-project hierarchy.
It is required because the settings file defines which projects are taking part in a <<multi_project_builds.adoc#multi_project_builds,multi-project build>>.
Besides defining included projects, you might need it to <<organizing_gradle_projects.adoc#organizing_gradle_projects,add libraries to your build script classpath>>.

The following example shows a standard Gradle project layout:

====
[.multi-language-sample]
Expand Down
Expand Up @@ -96,7 +96,7 @@ The `Project` object provides some standard properties, which are available in y
.Script with other targets
====
The _build scripts_ described here target `Project` objects.
There are also <<build_lifecycle.adoc#sec:settings_file,settings scripts>> and <<init_scripts.adoc#init_scripts,init scripts>> that respectively target link:{groovyDslPath}/org.gradle.api.initialization.Settings.html[Settings] and link:{groovyDslPath}/org.gradle.api.invocation.Gradle.html[Gradle] objects.
There are also <<organizing_gradle_projects.adoc#sec:settings_file,settings scripts>> and <<init_scripts.adoc#init_scripts,init scripts>> that respectively target link:{groovyDslPath}/org.gradle.api.initialization.Settings.html[Settings] and link:{groovyDslPath}/org.gradle.api.invocation.Gradle.html[Gradle] objects.
====

[[sec:the_script_api]]
Expand Down
Expand Up @@ -143,7 +143,7 @@ Kotlin DSL script files use the `.gradle.kts` file name extension.

To use the Kotlin DSL, simply name your files `build.gradle.kts` instead of `build.gradle`.

The <<build_lifecycle.adoc#sec:settings_file,settings file>>, `settings.gradle`, can also be renamed `settings.gradle.kts`.
The <<organizing_gradle_projects.adoc#sec:settings_file,settings file>>, `settings.gradle`, can also be renamed `settings.gradle.kts`.

In a multi-project build, you can have some modules using the Groovy DSL (with `build.gradle`) and others using the Kotlin DSL (with `build.gradle.kts`).

Expand Down
Expand Up @@ -297,7 +297,7 @@ The `layout` method taking a configuration block has been removed and is replace
A Gradle build is defined by its `settings.gradle(.kts)` file found in the current or parent directory.
Without a settings file, a Gradle build is undefined and Gradle produces an error when attempting to execute tasks.

To fix this error, <<build_lifecycle.adoc#sec:settings_file,create a `settings.gradle(.kts)` file>> for the build.
To fix this error, <<organizing_gradle_projects.adoc#sec:settings_file,create a `settings.gradle(.kts)` file>> for the build.

Exceptions to this are invoking Gradle with the `init` task or using diagnostic command line flags, such as `--version`.

Expand Down
Expand Up @@ -107,7 +107,7 @@ Overall, the anatomy of a typical project root directory looks roughly as follow
<4> Contains the JAR file and configuration of the <<gradle_wrapper.adoc#gradle_wrapper,Gradle Wrapper>>
<5> Project-specific <<build_environment.adoc#sec:gradle_configuration_properties,Gradle configuration properties>>
<6> Scripts for executing builds using the <<gradle_wrapper.adoc#gradle_wrapper,Gradle Wrapper>>
<7> The project's <<build_lifecycle.adoc#sec:settings_file, settings file>> where the list of subprojects is defined
<7> The project's <<organizing_gradle_projects.adoc#sec:settings_file, settings file>> where the list of subprojects is defined
<8> Usually a project is organized into one or multiple subprojects
<9> Each subproject has its own Gradle build script

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,18 +1,17 @@
// tag::after-evaluate[]
allprojects {
afterEvaluate { project ->
if (project.hasTests) {
println "Adding test task to $project"
project.task('test') {
doLast {
println "Running tests for $project"
}
gradle.beforeProject { project ->
project.ext.set("hasTests", false)
}

gradle.afterProject { project ->
if (project.ext.has("hasTests") && project.ext.get("hasTests") as Boolean) {
def projectString = project.toString()
println "Adding test task to $projectString"
project.task('test') {
doLast {
println "Running tests for $projectString"
}
}
}
}
// end::after-evaluate[]

allprojects {
ext.hasTests = false
}
@@ -1,15 +1,16 @@
// tag::after-evaluate[]
allprojects {
gradle.beforeProject {
// Set a default value
extra["hasTests"] = false
project.ext.set("hasTests", false)
}

afterEvaluate {
if (extra["hasTests"] as Boolean) {
println("Adding test task to $project")
tasks.register("test") {
doLast {
println("Running tests for $project")
}
gradle.afterProject {
if (project.ext.has("hasTests") && project.ext.get("hasTests") as Boolean) {
val projectString = project.toString()
println("Adding test task to $projectString")
tasks.register("test") {
doLast {
println("Running tests for $projectString")
}
}
}
Expand Down