File tree Expand file tree Collapse file tree
buildSrc/src/main/java/com/baeldung Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ repositories {
2+ mavenCentral()
3+ }
4+ apply plugin : ' java'
5+ apply plugin : ' maven'
6+ apply plugin : com.baeldung.GreetingPlugin
7+ dependencies {
8+ compile gradleApi()
9+ }
10+
11+ greeting {
12+ greeter = " Stranger"
13+ message = " Message from the build script!"
14+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ import org .gradle .api .Plugin ;
4+ import org .gradle .api .Project ;
5+
6+ public class GreetingPlugin implements Plugin <Project > {
7+ @ Override
8+ public void apply (Project project ) {
9+
10+ GreetingPluginExtension extension = project .getExtensions ().create ("greeting" , GreetingPluginExtension .class );
11+
12+ project .task ("hello" ).doLast (task -> {
13+ System .out .println ("Hello, " + extension .getGreeter ());
14+ System .out .println ("I have a message for You: " + extension .getMessage ()); }
15+ );
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung ;
2+
3+ public class GreetingPluginExtension {
4+ private String greeter = "Baeldung" ;
5+ private String message = "Message from Plugin!" ;
6+
7+ public String getGreeter () {
8+ return greeter ;
9+ }
10+
11+ public void setGreeter (String greeter ) {
12+ this .greeter = greeter ;
13+ }
14+
15+ public String getMessage () {
16+ return message ;
17+ }
18+
19+ public void setMessage (String message ) {
20+ this .message = message ;
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments