Gradle Project: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
 
(41 intermediate revisions by the same user not shown)
Line 6: Line 6:
* [[Gradle_Concepts#Project|Gradle Concepts]]
* [[Gradle_Concepts#Project|Gradle Concepts]]
* [[build.gradle]]
* [[build.gradle]]
* [[Gradle Logging]]


=Overview=
=Overview=


A Gradle project typically represents a software component to be built by executing a set of [[Gradle Task#Overview|tasks]] in sequence. A project has a direct class representation in the Gradle domain model: [https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html org.gradle.api.Project].
A Gradle project typically represents a software component to be built by executing a set of [[Gradle Task#Overview|tasks]] in sequence. A project has a direct class representation in the Gradle domain model: [https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html org.gradle.api.Project]. The Project instance is exposed for query and modification via the [[build.gradle]] file. Each project has its own [[build.gradle]] file.


The project instance is available to the [[build.gradle]] script via the <code>project</code> variable, which corresponds to the [https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getProject-- Project.getProject()] accessor. The project instance is not available in [[settings.gradle]], only the root project descriptor via <code>rootProject</code> variable, which corresponds to [https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/Settings.html#getRootProject-- Settings.getRootProject()].
The project instance is available to the [[build.gradle]] script via the <code>project</code> variable, which corresponds to the [https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getProject-- Project.getProject()] accessor. The project instance is not available in [[settings.gradle]], only the root project descriptor via <code>rootProject</code> variable, which corresponds to [https://docs.gradle.org/current/javadoc/org/gradle/api/initialization/Settings.html#getRootProject-- Settings.getRootProject()]. You are not required to use the <code>project</code> variable when accessing properties and methods of the project from [[build.gradle]], it is assumed you mean the Project instance.


=Project API and build.gradle DSL=
=Project API and build.gradle DSL=
Line 21: Line 22:
}
}
</syntaxhighlight>
</syntaxhighlight>
More details are available in: {{Internal|Gradle Build Script Classpath|Build Script Classpath}}
See: {{Internal|Gradle Build Script Classpath|Build Script Classpath}}
<span id='Using_a_Plugin'></span>Plugins for the build can be declare with [https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/PluginAware.html#apply-java.util.Map- PluginAware.apply(...)], which corresponds to the "apply" DSL element:
<span id='Using_a_Plugin'></span>Plugins for the build can be declare with [https://docs.gradle.org/current/javadoc/org/gradle/api/plugins/PluginAware.html#apply-java.util.Map- PluginAware.apply(...)], which corresponds to the "apply" DSL element:
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
apply plugin:|from: '...'
apply plugin:|from: '...'
</syntaxhighlight>
</syntaxhighlight>
More details on using plugins are available in: {{Internal|Gradle_Plugin_Concepts#Using_a_Plugin|Using a Plugin}}
See: {{Internal|Gradle_Plugin_Concepts#Using_a_Plugin|Using a Plugin}}
 
<span id='Project_Coordinates_1'></span>The project's coordinates and other state properties are available through a series of DSL variables: [[Gradle_Project_Coordinates,_State_and_Configured_Properties#Name|name]], [[Gradle_Project_Coordinates,_State_and_Configured_Properties#Group|group]], [[Gradle_Project_Coordinates,_State_and_Configured_Properties#Version|version]], [[Gradle_Project_Coordinates,_State_and_Configured_Properties#Description|description]], [[Gradle_Project_Coordinates,_State_and_Configured_Properties#Path|path]], etc. Some of the coordinates, such as "group" and "version" can be also set in [[build.gradle]] with a variable assignment, while others, such as "name" cannot be changed.
<syntaxhighlight lang='groovy'>
group = "io.playground"
version = "0.1.0"
description = "Example project"
logger.info "Project coordinates: ${group} ${name} ${version} ${description} ${path}"
</syntaxhighlight>See: {{Internal|Gradle_Project_Coordinates,_State_and_Configured_Properties#Overview|Gradle Project Coordinates and State Properties}}
The project logger is also accessible in [[build.gradle]]. See: {{Internal|Gradle_Logging|Gradle Logging}}
 
<span id='Dependencies'></span>Dependencies and configurations can be managed with the "dependencies" and "configurations" DSL elements:
<span id='Dependencies'></span>Dependencies and configurations can be managed with the "dependencies" and "configurations" DSL elements:
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
Line 35: Line 46:
   // configuration closure
   // configuration closure
}
}
</syntaxhighlight>More details in: {{Internal|Gradle Dependencies and Configurations|Gradle Dependencies and Configurations}}
</syntaxhighlight>See: {{Internal| Gradle Dependencies and Dependency Configurations|Gradle Dependencies and Dependency Configurations}}
<span id='Gradle_File_Resolution'></span>The DSL exposes project-level methods for file resolution:
<syntaxhighlight lang='groovy'>
File f = file('./some/path/inside/project')
</syntaxhighlight>See: {{Internal|Gradle File Resolution|Gradle File Resolution}}
 
The project allows declaring new tasks in [[build.gradle]] and also defining completely new tasks in-line. See: {{Internal|Gradle Task#Overview|Gradle Tasks}}
 
=build.gradle Example=
{{Internal|build.gradle#Example|build.gradle Example}}
 
=<span id='Project_Coordinates'></span>Prject Coordinates and State Properties=
 
{{Internal|Gradle_Project_Coordinates,_State_and_Configured_Properties#Coordinates|Gradle Project Coordinates, State and Configured Properties}}
====Project Name====
{{Internal|Gradle_Project_Coordinates,_State_and_Configured_Properties#Name|Gradle Project Coordinates, State and Configured Properties &#124; Project Name}}
====Build Directory====
{{Internal|Gradle_Project_Coordinates,_State_and_Configured_Properties#Build_Directory|Gradle Project Coordinates, State and Configured Properties &#124; Build Directory}}


=Project Directory=
=Multi-Project Builds=
=Multi-Project Builds=
{{Internal|Gradle Multi-Project Builds#Overview|Multi-Project Builds}}
{{Internal|Gradle Multi-Project Builds#Overview|Multi-Project Builds}}
=Project Structure=
A project contains:
==Task Container==
A '''task container''', available via the [https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#getTasks-- Project.getTasks()] method call. The task container manages the project's [[Gradle_Task#Overview|tasks]]. Also see: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskContainer.html
=TO DEPLETE=
=TO DEPLETE=
{{Internal|Gradle Project and Build Script|Gradle Project and Build Script}}
{{Internal|Gradle Project and Build Script|Gradle Project and Build Script}}

Latest revision as of 06:59, 28 March 2021

External

Internal

Overview

A Gradle project typically represents a software component to be built by executing a set of tasks in sequence. A project has a direct class representation in the Gradle domain model: org.gradle.api.Project. The Project instance is exposed for query and modification via the build.gradle file. Each project has its own build.gradle file.

The project instance is available to the build.gradle script via the project variable, which corresponds to the Project.getProject() accessor. The project instance is not available in settings.gradle, only the root project descriptor via rootProject variable, which corresponds to Settings.getRootProject(). You are not required to use the project variable when accessing properties and methods of the project from build.gradle, it is assumed you mean the Project instance.

Project API and build.gradle DSL

The build script classpath for the project can be configured with Project.buildscript(Closure) which corresponds to the "buildscript" DSL element:

buildscript {
  // configuration closure
}

See:

Build Script Classpath

Plugins for the build can be declare with PluginAware.apply(...), which corresponds to the "apply" DSL element:

apply plugin:|from: '...'

See:

Using a Plugin

The project's coordinates and other state properties are available through a series of DSL variables: name, group, version, description, path, etc. Some of the coordinates, such as "group" and "version" can be also set in build.gradle with a variable assignment, while others, such as "name" cannot be changed.

group = "io.playground"
version = "0.1.0"
description = "Example project"
logger.info "Project coordinates: ${group} ${name} ${version} ${description} ${path}"

See:

Gradle Project Coordinates and State Properties

The project logger is also accessible in build.gradle. See:

Gradle Logging

Dependencies and configurations can be managed with the "dependencies" and "configurations" DSL elements:

dependencies {
  // configuration closure
}
configurations {
  // configuration closure
}

See:

Gradle Dependencies and Dependency Configurations

The DSL exposes project-level methods for file resolution:

File f = file('./some/path/inside/project')

See:

Gradle File Resolution

The project allows declaring new tasks in build.gradle and also defining completely new tasks in-line. See:

Gradle Tasks

build.gradle Example

build.gradle Example

Prject Coordinates and State Properties

Gradle Project Coordinates, State and Configured Properties

Project Name

Gradle Project Coordinates, State and Configured Properties | Project Name

Build Directory

Gradle Project Coordinates, State and Configured Properties | Build Directory

Multi-Project Builds

Multi-Project Builds

Project Structure

A project contains:

Task Container

A task container, available via the Project.getTasks() method call. The task container manages the project's tasks. Also see: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskContainer.html

TO DEPLETE

Gradle Project and Build Script