From f58b531ad7be9961d2ca30c5ffebd42e663775bb Mon Sep 17 00:00:00 2001 From: Dmitry Fedotov Date: Sun, 14 Apr 2024 14:13:46 +0300 Subject: [PATCH] Add Gradle Build File Basics page. --- .../gradle/core-concepts/build_file_basics.md | 79 +++++++++++++++++++ ...file-basics.md => settings_file_basics.md} | 0 2 files changed, 79 insertions(+) create mode 100644 docs/gradle/core-concepts/build_file_basics.md rename docs/gradle/core-concepts/{settings-file-basics.md => settings_file_basics.md} (100%) 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 similarity index 100% rename from docs/gradle/core-concepts/settings-file-basics.md rename to docs/gradle/core-concepts/settings_file_basics.md -- 2.39.5