Gradle Plugin Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 25: Line 25:


=Using a Plugin=
=Using a Plugin=
Plugins can be applied in two ways, via the [[#apply.28.29_Method|apply]] method or via the [[Gradle_Plugin_Concepts#plugins_script_block|plugins script block]].
Plugins can be applied in two ways, via the [[#apply.28.29_Method|apply]] method or via the [[Gradle_Plugin_Concepts#plugins_Script_Block|plugins script block]].
==apply() Method==
==apply() Method==
apply() is a method of the [[Gradle PluginAware|org.gradle.api.plugins.PluginAware]] interface that is inherited by [[Gradle Project|Project]], [[Gradle Settings|Settings]] and [[org.gradle.api.invocation.Gradle|Gradle]].  
apply() is a method of the [[Gradle PluginAware|org.gradle.api.plugins.PluginAware]] interface that is inherited by [[Gradle Project|Project]], [[Gradle Settings|Settings]] and [[org.gradle.api.invocation.Gradle|Gradle]].  

Revision as of 05:19, 24 September 2020

External

Internal

TODO

Gradle Plugins TODEPLETE

Overview

A Gradle plugin is packaged code that uses the Gradle API to provide additional functionality and extend Gradle core. A Gradle plugin applies some configuration to a target object, usually a Project. The plugin may introduce new tasks, new domain objects, conventions, project layouts and patterns for a specific problem domain. Plugins may even extend the core objects. Introducing their own conventions, plugins are "opinionated", encouraging the user to do things in a certain way. However, well written plugins must provide means to change the default conventions and make it work for non-standard projects.

Plugin API

org.gradle.api.Plugin<T>

Script Plugin

https://docs.gradle.org/current/userguide/plugins.html#sec:script_plugins

A script plugin is simply a file containing Gradle DSL code and possibly in-line Java and Groovy code. It can be thought as just another build script that can be imported into a build script.

apply from: 'example.gradle'

Conventionally, the file has the ".gradle" extension, but this is not mandatory. The file can be loaded from the local filesystem, or from a remote location. Filesystem location is relative to the project directory. Remote locations are specified with HTTP URLs.

Binary Plugin

A binary plugin is a class implementing org.gradle.api.Plugin and ancillary classes.

Using a Plugin

Plugins can be applied in two ways, via the apply method or via the plugins script block.

apply() Method

apply() is a method of the org.gradle.api.plugins.PluginAware interface that is inherited by Project, Settings and Gradle.

apply plugin: 'java'

plugins Script Block

plugins {
}

Plugin Extension

A plugin is a typical use case for an extension.

Standard Plugins

A standard plugin ships with the Gradle runtime.

Plugin Libraries

External Plugins

Writing Custom Plugins

Custom Binary Plugins