Skip to content

Commit ac5cda9

Browse files
committed
generate the wrapper scripts using gradle
1 parent 978ecee commit ac5cda9

File tree

5 files changed

+66
-282
lines changed

5 files changed

+66
-282
lines changed

grails-profiles/base/build.gradle

+6-2
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ dependencies {
3838
TaskProvider<Copy> copyWrapper = tasks.register('copyGrailsWrapperScripts', Copy)
3939
copyWrapper.configure { Copy copy ->
4040
Project wrapperProject = rootProject.project(':grails-wrapper')
41-
copy.from(wrapperProject.layout.projectDirectory.dir('shell'))
42-
copy.from(wrapperProject.tasks.named('jar').get().outputs)
41+
copy.dependsOn(wrapperProject.tasks.named('installDist'))
42+
copy.from(wrapperProject.layout.buildDirectory.dir('install/grails-wrapper'))
4343
copy.into(project.layout.projectDirectory.dir('skeleton'))
4444
}
4545

46+
tasks.named('sourcesProfileJar').configure {
47+
it.dependsOn(copyWrapper)
48+
}
49+
4650
tasks.named('processProfileResources').configure {
4751
it.dependsOn(copyWrapper)
4852
}

grails-profiles/profile/build.gradle

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ dependencies {
3636
TaskProvider<Copy> copyWrapper = tasks.register('copyGrailsWrapperScripts', Copy)
3737
copyWrapper.configure { Copy copy ->
3838
Project wrapperProject = rootProject.project(':grails-wrapper')
39-
copy.from(wrapperProject.layout.projectDirectory.dir('shell'))
40-
copy.from(wrapperProject.tasks.named('jar').get().outputs)
39+
copy.dependsOn(wrapperProject.tasks.named('installDist'))
40+
copy.from(wrapperProject.layout.buildDirectory.dir('install/grails-wrapper'))
4141
copy.into(project.layout.projectDirectory.dir('skeleton'))
4242
}
4343

44+
tasks.named('sourcesProfileJar').configure {
45+
it.dependsOn(copyWrapper)
46+
}
47+
4448
tasks.named('processProfileResources').configure {
4549
it.dependsOn(copyWrapper)
4650
}

grails-wrapper/build.gradle

+54-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
plugins {
1919
id 'java'
20+
id 'distribution'
2021
}
2122

2223
version = projectVersion
@@ -31,6 +32,7 @@ ext {
3132
'puneetbehl' : 'Puneet Behl'
3233
]
3334
cliProject = true
35+
startMainClass = 'grails.init.Start'
3436
}
3537

3638
// Intentionally no dependencies to prevent bloat
@@ -40,9 +42,58 @@ apply {
4042
from rootProject.layout.projectDirectory.file('gradle/publish-config.gradle')
4143
}
4244

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
4551
it.manifest {
46-
attributes 'Main-Class': 'grails.init.Start'
52+
attributes 'Main-Class': project.property('startMainClass')
4753
}
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
4899
}

grails-wrapper/shell/grailsw

-169
This file was deleted.

grails-wrapper/shell/grailsw.bat

-106
This file was deleted.

0 commit comments

Comments
 (0)