From: Dmitry Fedotov Date: Sun, 14 Apr 2024 11:13:46 +0000 (+0300) Subject: Add Gradle Build File Basics page. X-Git-Url: https://www.git.dmfe.net/?a=commitdiff_plain;h=f58b531ad7be9961d2ca30c5ffebd42e663775bb;p=dmfe-website Add Gradle Build File Basics page. --- diff --git a/docs/gradle/core-concepts/build_file_basics.md b/docs/gradle/core-concepts/build_file_basics.md new file mode 100644 index 0000000..5accb75 --- /dev/null +++ b/docs/gradle/core-concepts/build_file_basics.md @@ -0,0 +1,79 @@ +--- +sidebar_position: 5 +tags: + - gradle + - build tool + - build file +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Build File Basics + +A build script details build configuration, tasks, and plugins. +Every Gradle build comprises at least one build script. +In the build file, two types of dependencies can be added: +1. The libraries and/or plugins on which Gradle and the build script depend. +2. The libraries on which the project sources depend. + +## Build script + +The build script is either a `build.gradle` file written in Groovy or a +`build.gradle.kts` file in Kotlin. +Example of the build script: + + + ```kotlin title="󱈙 settings.gradle.kts" + plugins { + id("application") (1) + } + + application { + mainClass = "com.example.Main" (2) + } + ``` + + + ```groovy title=" settings.gradle" + plugins { + id 'application' (1) + } + + application { + mainClass = 'com.example.Main' (2) + } + ``` + + + +(1) Add plugins. +(2) Use convention properties. + +### 1. Add plugins + +Plugins extend Gradle's functionality and can add more tasks to a project. +Adding a plugin to a build is called _applying_ a plugin: +```kotlin +plugins { + id("application") +} +``` +The application plugin facilitates creating an executable JVM application. +Applying the [Application plugin](https://docs.gradle.org/current/userguide/application_plugin.html#application_plugin) +also implicitly applies the [Java plugin](https://docs.gradle.org/current/userguide/java_plugin.html#java_plugin). +The `java` plugin adds Java compilation along with testing and bundling capabilities to a project. + +### 2. Use convention properties + +A plugin adds tasks to a project. It also adds properties and methods to a project. +The `application` plugin defines tasks that package and distribute an application, +such as the `run` task. +The Application plugin provides a way to declare the main class of a Java application, +which is required to execute the code. +```kotlin +application { + mainClass = "com.example.Main" +} +``` + diff --git a/docs/gradle/core-concepts/settings-file-basics.md b/docs/gradle/core-concepts/settings-file-basics.md deleted file mode 100644 index 7dec86c..0000000 --- a/docs/gradle/core-concepts/settings-file-basics.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -sidebar_position: 4 -tags: - - gradle - - build tool - - settings ---- - -import Tabs from '@theme/Tabs'; -import TabItem from '@theme/TabItem'; - -# Settings File Basics - -Settings file is the **entry point** of every Gradle project. -The primary purpose of the _settings file_ is to add subprojects to your build. -Gradle supports single and multi-project builds. -- Settings file is optional for single-project builds. -- Settings file is mandatory and declares all subprojects for multi-project builds. - -## Settings script - -The settings file is a script. It is either a `settings.gradle` file written in Groovy -or a `settings.gradle.kts` file in Kotlin. -The _Groovy DSL_ and _Kotlin DSL_ are the only accepted languages for Gradle scripts. -The settings file is typically found in the root directory of the project: - - - ```kotlin title="󱈙 settings.gradle.kts" - rootProject.name = "root-project" (1) - - include("sub-project-a") (2) - include("sub-project-b") - include("sub-project-c") - ``` - - - ```groovy title=" settings.gradle" - rootProject.name = 'root-project' (1) - - include('sub-project-a') (2) - include('sub-project-b') - include('sub-project-c') - ``` - - - -(1) Define the project name. -(2) Add subprojects. - diff --git a/docs/gradle/core-concepts/settings_file_basics.md b/docs/gradle/core-concepts/settings_file_basics.md new file mode 100644 index 0000000..7dec86c --- /dev/null +++ b/docs/gradle/core-concepts/settings_file_basics.md @@ -0,0 +1,49 @@ +--- +sidebar_position: 4 +tags: + - gradle + - build tool + - settings +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# Settings File Basics + +Settings file is the **entry point** of every Gradle project. +The primary purpose of the _settings file_ is to add subprojects to your build. +Gradle supports single and multi-project builds. +- Settings file is optional for single-project builds. +- Settings file is mandatory and declares all subprojects for multi-project builds. + +## Settings script + +The settings file is a script. It is either a `settings.gradle` file written in Groovy +or a `settings.gradle.kts` file in Kotlin. +The _Groovy DSL_ and _Kotlin DSL_ are the only accepted languages for Gradle scripts. +The settings file is typically found in the root directory of the project: + + + ```kotlin title="󱈙 settings.gradle.kts" + rootProject.name = "root-project" (1) + + include("sub-project-a") (2) + include("sub-project-b") + include("sub-project-c") + ``` + + + ```groovy title=" settings.gradle" + rootProject.name = 'root-project' (1) + + include('sub-project-a') (2) + include('sub-project-b') + include('sub-project-c') + ``` + + + +(1) Define the project name. +(2) Add subprojects. +