Skip to content

Commit

Permalink
Precompiled script plugin README
Browse files Browse the repository at this point in the history
  • Loading branch information
rivancic committed May 29, 2021
1 parent 2a42953 commit a4b7107
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
6 changes: 3 additions & 3 deletions precompiled-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Gradle Precompiled Script Plugin
# Gradle Precompiled Plugin

This directory contains assignments and examples with the focus on precompiled Gradle plugins.

Script or source code for the plugin has to go into **buildSrc** directory based on the Gradle convention.

| Module | Description | Resources |
| ------------- |:-------------:|-------------:|
| **[precompiled-script-plugin](precompiled-script-plugin)** | Script plugin transformed into precompiled script plugin. This is supported with **groovy-gradle-plugin** plugin. This way plugin can be reused in multiple subprojects. One can also start to extract Gradle components into separate classes. | Precompiled script plugin resource |
| **[precompiled-plugin](precompiled-plugin)** | Precompiled script plugin transformed into standard precompiled plugin. Now whole part of script plugin is extracted into standalone components. Code can be structured as in a standard Java / Groovy / Kotlin application. | Precompiled plugin resource |
| **[precompiled-script-plugin](precompiled-script-plugin)** | Script plugin transformed into precompiled script plugin. This is supported with **groovy-gradle-plugin** plugin. This way plugin can be reused in multiple subprojects. Gradle components can be extracted into separate classes. | Precompiled script plugin resource |
| **[precompiled-plugin](precompiled-plugin)** | Precompiled script plugin transformed into standard precompiled plugin. Now whole part of script plugin is extracted into standalone components. Code is structured as in a standard Java / Groovy / Kotlin application. | Precompiled plugin resource |

**Precompiled plugin external resources**

Expand Down
25 changes: 16 additions & 9 deletions precompiled-plugin/precompiled-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ One of the main benefits of using precompiled plugin instead of script plugins i
You will be able to structure code as in your ordinary JVM code. Code intended to be packaged in the plugin itself should be located under the **main** directory. Inside it packages can be used to structure the code.

<p width="100%">
<img src="readme-content/gradle-precompiled-plugin.png" alt="Java library applying remote modular script plugin" width="802">
<img src="readme-content/gradle-precompiled-plugin.png" alt="Gradle precompiled plugin" width="400">
</p>

Tasks and plugins defined in the buildSrc will be available to all the build scripts inside the main project.
Expand All @@ -28,14 +28,21 @@ https://docs.gradle.org/current/userguide/custom_tasks.html

## Components of the build script plugin

- Project
Applying module that is compiled in buildSrc and made available for all the projects
- buildSrc
Containing source code for the Gradle plugin. It's picked up automatically by Gradle. Content of the buildSrc is the same as of any other Java based project.
Source code in src/main/[groovy/java/kotlin]
Plugin is represented by the class extending the Plugin interface
src/main/resources contains META-INF.gradle-plugins/{pluginName}.properties file that specifies short version of the plugin name.
Content will be compiled and result persisted in internal build folder.
### Project

Applying module that is compiled in buildSrc and made available for all the projects

### buildSrc

buildSrc directory contains source code for the Gradle plugin. Content of this directory is automatically processed by
the Gradle itself. Content of the buildSrc is the same as of any other Java based project.
Source code should reside in src/main/[groovy/java/kotlin].
Plugin is represented by the class extending the Plugin interface
Content will be compiled and result persisted in internal build folder.

### Plugin name

// TODO show how to specify plugin name instead of using full package name of the class implementing the plugin.

src/main/resources contains META-INF.gradle-plugins/{pluginName}.properties file that specifies short version of the plugin name.

42 changes: 42 additions & 0 deletions precompiled-plugin/precompiled-script-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Precompiled Script Plugin

Till now all the build logic was contained in the build script. Precompiled script plugin allow you to package whole
build script written in DSL language as in Groovy or Kotlin to package it as a plugin from buildSrc directory.
It will be compiled into class files and packaged into a jar. For all intents and purposes, they are binary plugins and
can be applied by plugin ID, tested and published as binary plugins.

The benefit you will now receive is that you can extract step by step build logic in stand-alone classes inside the
buildSrc directory or add new logic in same way. This can be an intermediate step to rewriting script logic into
precompiled or stand-alone binary plugin.

In this project we will builds on top of [previous project](../../script-plugin/simple-script-plugin), it moves build
logic into separate module. Plugin will still be defined in a script file. To create a plugin out of build script under buildSrc we
have to add [groovy-gradle-plugin](https://plugins.gradle.org/plugin/dev.gradleplugins.groovy-gradle-plugin) to buildSrc itself.

## Code structure

Script for the plugin has to be located under buildScr/main/groovy or buildSrc/main/kotlin package.
The name of the plugin by which you will be able to reference it will be the same as the filename of the script itself
without the extension. In case that the filename is **precompiled-script-plugin.gradle** Then the
plugin id will be filename without the extension (.gradle).

- Filename: precompiled-script-plugin.gradle
- Plugin id: precompiled-script-plugin

<p width="100%">
<img src="readme-content/gradle-precompiled-script-plugin.png" alt="Gradle precompiled script plugin" width="400">
</p>

Gradle script defined in buildSrc will be available to all the build scripts inside the main project as a plugin.

## Components of the build script plugin

### Project

Applying plugin that is compiled in buildSrc from the script and made available for all the projects.

### buildSrc

Containing Gradle script that will be available as a plugin. It's compiled with the help of groovy-gradle-plugin.
Content will be compiled and result persisted in internal build folder.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a4b7107

Please sign in to comment.