31
31
import org .gradle .api .file .FileCollection ;
32
32
import org .gradle .api .plugins .ApplicationPlugin ;
33
33
import org .gradle .api .plugins .ApplicationPluginConvention ;
34
+ import org .gradle .api .tasks .TaskProvider ;
34
35
import org .gradle .jvm .application .scripts .TemplateBasedScriptGenerator ;
35
36
import org .gradle .jvm .application .tasks .CreateStartScripts ;
36
37
@@ -49,26 +50,29 @@ public void execute(Project project) {
49
50
Distribution distribution = distributions .create ("boot" );
50
51
distribution .getDistributionBaseName ()
51
52
.convention ((project .provider (() -> applicationConvention .getApplicationName () + "-boot" )));
52
- CreateStartScripts bootStartScripts = project .getTasks ().create ("bootStartScripts" , CreateStartScripts .class );
53
- bootStartScripts
54
- .setDescription ("Generates OS-specific start scripts to run the project as a Spring Boot application." );
55
- ((TemplateBasedScriptGenerator ) bootStartScripts .getUnixStartScriptGenerator ())
56
- .setTemplate (project .getResources ().getText ().fromString (loadResource ("/unixStartScript.txt" )));
57
- ((TemplateBasedScriptGenerator ) bootStartScripts .getWindowsStartScriptGenerator ())
58
- .setTemplate (project .getResources ().getText ().fromString (loadResource ("/windowsStartScript.txt" )));
59
- project .getConfigurations ().all ((configuration ) -> {
60
- if ("bootArchives" .equals (configuration .getName ())) {
61
- CopySpec libCopySpec = project .copySpec ().into ("lib" )
62
- .from ((Callable <FileCollection >) () -> configuration .getArtifacts ().getFiles ());
63
- libCopySpec .setFileMode (0644 );
64
- distribution .getContents ().with (libCopySpec );
65
- bootStartScripts .setClasspath (configuration .getArtifacts ().getFiles ());
66
- }
67
- });
68
- bootStartScripts .getConventionMapping ().map ("outputDir" , () -> new File (project .getBuildDir (), "bootScripts" ));
69
- bootStartScripts .getConventionMapping ().map ("applicationName" , applicationConvention ::getApplicationName );
70
- bootStartScripts .getConventionMapping ().map ("defaultJvmOpts" ,
71
- applicationConvention ::getApplicationDefaultJvmArgs );
53
+ TaskProvider <CreateStartScripts > bootStartScripts = project .getTasks ().register ("bootStartScripts" ,
54
+ CreateStartScripts .class , (bss ) -> {
55
+ bss .setDescription (
56
+ "Generates OS-specific start scripts to run the project as a Spring Boot application." );
57
+ ((TemplateBasedScriptGenerator ) bss .getUnixStartScriptGenerator ()).setTemplate (
58
+ project .getResources ().getText ().fromString (loadResource ("/unixStartScript.txt" )));
59
+ ((TemplateBasedScriptGenerator ) bss .getWindowsStartScriptGenerator ()).setTemplate (
60
+ project .getResources ().getText ().fromString (loadResource ("/windowsStartScript.txt" )));
61
+
62
+ project .getConfigurations ().all ((configuration ) -> {
63
+ if ("bootArchives" .equals (configuration .getName ())) {
64
+ CopySpec libCopySpec = project .copySpec ().into ("lib" )
65
+ .from ((Callable <FileCollection >) () -> configuration .getArtifacts ().getFiles ());
66
+ libCopySpec .setFileMode (0644 );
67
+ distribution .getContents ().with (libCopySpec );
68
+ bss .setClasspath (configuration .getArtifacts ().getFiles ());
69
+ }
70
+ });
71
+ bss .getConventionMapping ().map ("outputDir" , () -> new File (project .getBuildDir (), "bootScripts" ));
72
+ bss .getConventionMapping ().map ("applicationName" , applicationConvention ::getApplicationName );
73
+ bss .getConventionMapping ().map ("defaultJvmOpts" ,
74
+ applicationConvention ::getApplicationDefaultJvmArgs );
75
+ });
72
76
CopySpec binCopySpec = project .copySpec ().into ("bin" ).from (bootStartScripts );
73
77
binCopySpec .setFileMode (0755 );
74
78
distribution .getContents ().with (binCopySpec );
0 commit comments