BAEL-1349: Custom plugin added to Gradle (#3145)
This commit is contained in:
parent
080d1a9425
commit
9046955197
|
@ -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!"
|
||||
}
|
|
@ -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()); }
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue