BAEL-1349: Custom plugin added to Gradle (#3145)

This commit is contained in:
Wosin 2017-12-11 16:32:04 +01:00 committed by Grzegorz Piwowarek
parent 080d1a9425
commit 9046955197
3 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,14 @@
repositories{
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: com.baeldung.GreetingPlugin
dependencies {
compile gradleApi()
}
greeting {
greeter = "Stranger"
message = "Message from the build script!"
}

View File

@ -0,0 +1,17 @@
package com.baeldung;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
public class GreetingPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
GreetingPluginExtension extension = project.getExtensions().create("greeting", GreetingPluginExtension.class);
project.task("hello").doLast(task -> {
System.out.println("Hello, " + extension.getGreeter());
System.out.println("I have a message for You: " + extension.getMessage()); }
);
}
}

View File

@ -0,0 +1,22 @@
package com.baeldung;
public class GreetingPluginExtension {
private String greeter = "Baeldung";
private String message = "Message from Plugin!";
public String getGreeter() {
return greeter;
}
public void setGreeter(String greeter) {
this.greeter = greeter;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}