17
17
18
18
plugins {
19
19
id ' java'
20
+ id ' distribution'
20
21
}
21
22
22
23
version = projectVersion
31
32
' puneetbehl' : ' Puneet Behl'
32
33
]
33
34
cliProject = true
35
+ startMainClass = ' grails.init.Start'
34
36
}
35
37
36
38
// Intentionally no dependencies to prevent bloat
@@ -40,9 +42,58 @@ apply {
40
42
from rootProject. layout. projectDirectory. file(' gradle/publish-config.gradle' )
41
43
}
42
44
43
- tasks. named(' jar' , Jar ). configure { Jar it ->
44
- it. archiveFileName = " grails-wrapper.jar"
45
+ // It's surprisingly hard to generate start scripts and *not* have them nested into a bin / lib directory
46
+ // rather than defining the application and then having to add tasks to rework it, just define a distribution and
47
+ // create the scripts in the right location from the start
48
+ TaskProvider<Jar > jarTask = tasks. named(' jar' , Jar )
49
+ jarTask. configure { Jar it ->
50
+ it. archiveFileName = " ${ project.name} .jar" as String
45
51
it. manifest {
46
- attributes ' Main-Class' : ' grails.init.Start '
52
+ attributes ' Main-Class' : project . property( ' startMainClass ' )
47
53
}
54
+ }
55
+
56
+ TaskProvider<CreateStartScripts > startScripts = tasks. register(' createStartScripts' , CreateStartScripts )
57
+ startScripts. configure { CreateStartScripts t ->
58
+ t. outputDir = layout. buildDirectory. dir(' generated-scripts' ). get(). asFile
59
+ t. applicationName = ' grailsw'
60
+ t. mainClass = project. findProperty(' startMainClass' ) as String
61
+ t. classpath = files(jarTask)
62
+
63
+ // See gradle tickets such as for lib https://github.com/gradle/gradle/issues/7033
64
+ doLast {
65
+ t. unixScript. text = t. unixScript. text
66
+ .replace(' $APP_HOME/lib/' , ' $APP_HOME/' )
67
+ .replace(' "${APP_HOME:-./}.."' , ' "${APP_HOME:-./}"' )
68
+
69
+ t. windowsScript. text = t. windowsScript. text
70
+ .replace(' %APP_HOME%\\ lib\\ ' , ' %APP_HOME%\\ ' )
71
+ .replace(' "%APP_HOME%\\ lib\\ ' , ' "%APP_HOME%\\ ' )
72
+ .replace(' SET APP_HOME=%DIRNAME%..' , ' SET APP_HOME=%DIRNAME%' )
73
+ }
74
+ }
75
+
76
+ project. extensions. getByType(DistributionContainer ). configureEach {
77
+ it. contents {
78
+ from(jarTask) {
79
+ into ' '
80
+ }
81
+
82
+ from(startScripts) {
83
+ into ' '
84
+ }
85
+ }
86
+ }
87
+
88
+ tasks. named(' assemble' ). configure {
89
+ it. dependsOn(startScripts)
90
+ }
91
+ tasks. named(' installDist' ). configure {
92
+ it. dependsOn startScripts
93
+ }
94
+ tasks. named(' distZip' ). configure {
95
+ dependsOn startScripts
96
+ }
97
+ tasks. named(' distTar' ). configure {
98
+ dependsOn startScripts
48
99
}
0 commit comments