mirror of
https://github.com/ysoftdevs/gradle-training.git
synced 2026-01-11 22:41:09 +01:00
add custom groovy plugin and its usage from local Maven storage
This commit is contained in:
12
14-custom-groovy-plugin/build.gradle
Normal file
12
14-custom-groovy-plugin/build.gradle
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
apply plugin: "groovy"
|
||||||
|
apply plugin: "maven"
|
||||||
|
|
||||||
|
archivesBaseName = "lines-count"
|
||||||
|
version = "1.0"
|
||||||
|
group "com.ysoft.training"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile localGroovy()
|
||||||
|
compile gradleApi()
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.ysoft.training
|
||||||
|
|
||||||
|
import org.gradle.api.Plugin
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple plugin for counting lines in build.gradle.
|
||||||
|
**/
|
||||||
|
class LineCountPlugin implements Plugin<Project> {
|
||||||
|
|
||||||
|
void apply(Project project) {
|
||||||
|
Task countLineTask = project.tasks.add("countLines")
|
||||||
|
countLineTask.doLast {
|
||||||
|
def counter = 0
|
||||||
|
new File("build.gradle").eachLine { line ->
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
|
println "Total lines: ${counter}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
implementation-class=com.ysoft.training.LineCountPlugin
|
||||||
11
15-use-custom-plugin/build.gradle
Normal file
11
15-use-custom-plugin/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.ysoft.training:lines-count:1.0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
apply plugin: 'lines-count'
|
||||||
|
|
||||||
24
README.md
24
README.md
@@ -139,3 +139,27 @@ In this example plugin is stored as gist at Github
|
|||||||
|
|
||||||
gradle tasks
|
gradle tasks
|
||||||
gradle helloFromGist
|
gradle helloFromGist
|
||||||
|
|
||||||
|
|
||||||
|
## 14-custom-groovy-plugin
|
||||||
|
|
||||||
|
Example of stand alone plugin written in Groovy. Compile and install this
|
||||||
|
plugin to your local Maven repository. Then you will be able to use it in
|
||||||
|
the next example.
|
||||||
|
|
||||||
|
gradle install
|
||||||
|
|
||||||
|
Pay attention to special file: src/main/resources/META-INF/gradle-pluginslines-count.properties
|
||||||
|
This file will cause that it will be possible to apply plugin by it's id instead
|
||||||
|
of java class name. It's preferred solution in Gradle world, because it gives
|
||||||
|
you more flexibility when changing plugin implementation
|
||||||
|
|
||||||
|
|
||||||
|
## 15-use-custom-plugin
|
||||||
|
|
||||||
|
You need to install plugin to your local Maven storage (see example 14.).
|
||||||
|
This example shows how to include plugin from local Maven storage.
|
||||||
|
Plugin is just counting lines in build.gradle file in current directory.
|
||||||
|
|
||||||
|
gradle tasks
|
||||||
|
gradle countLines
|
||||||
|
|||||||
Reference in New Issue
Block a user