@@ -26,7 +26,7 @@ import org.grails.forge.internal.tasks.PicocliBuildCompletionTask
2626plugins {
2727 id ' groovy'
2828 id ' java-library'
29- id ' application '
29+ id ' distribution '
3030 id ' com.gradleup.shadow'
3131 id ' org.grails.forge.rocker'
3232}
@@ -62,6 +62,11 @@ configurations {
6262 }
6363}
6464
65+ ext {
66+ cliProject = true
67+ startMainClass = ' org.grails.forge.cli.Application'
68+ }
69+
6570dependencies {
6671 annotationProcessor platform(" io.micronaut:micronaut-bom:$micronautVersion " )
6772 implementation platform(" io.micronaut:micronaut-bom:$micronautVersion " )
@@ -103,18 +108,10 @@ dependencies {
103108 testImplementation " org.codehaus.groovy:groovy-test:$groovyVersion "
104109}
105110
106- application {
107- mainClass = ' org.grails.forge.cli.Application'
108- }
109-
110111rocker {
111112 postProcessing = [' org.grails.forge.rocker.plugin.WhitespaceProcessor' ]
112113}
113114
114- startScripts {
115- applicationName = ' grails-forge-cli'
116- }
117-
118115apply {
119116 from rootProject. layout. projectDirectory. file(' gradle/java-config.gradle' )
120117 from rootProject. layout. projectDirectory. file(' gradle/publish-config.gradle' )
@@ -124,7 +121,7 @@ apply {
124121}
125122
126123def generateManpageAsciiDoc = tasks. register(' generateManpageAsciiDoc' , GenerateManpageAsciidoc ) {
127- mainClass = application . mainClass
124+ mainClass = findProperty( ' startMainClass ' ) as String
128125 classpath. from(configurations. generateConfig, sourceSets. main. runtimeClasspath)
129126 outputDirectory = layout. buildDirectory. dir(' generated-picocli-docs' )
130127}
@@ -147,74 +144,83 @@ processManPages.configure { Sync it ->
147144
148145def buildCompletion = tasks. register(' buildCompletion' , PicocliBuildCompletionTask )
149146buildCompletion. configure { PicocliBuildCompletionTask it ->
150- it. outputDirectory. set(layout. buildDirectory. dir(' bin ' ))
147+ it. outputDirectory. set(layout. buildDirectory. dir(' build-completion ' ))
151148 it. classpath. from(sourceSets. main. runtimeClasspath)
152- it. mainClass. set(application . mainClass )
149+ it. mainClass. set(findProperty( ' startMainClass ' ) )
153150}
154151
155- distributions {
156- main {
157- contents {
158- from(buildCompletion) {
159- into ' bin'
160- }
161- from(rootProject. layout. projectDirectory. file(' LICENSE' )) {
162- into ' '
163- }
164- }
152+ TaskProvider<Jar > jarTask = tasks. named(' jar' , Jar )
153+ jarTask. configure { Jar it ->
154+ it. manifest {
155+ attributes ' Main-Class' : project. property(' startMainClass' )
165156 }
166157}
167158
168- tasks. named(' shadowJar' , ShadowJar ) {
159+ TaskProvider<Jar > shadowJarTask = tasks. named(' shadowJar' , ShadowJar )
160+ shadowJarTask. configure { ShadowJar it ->
161+ it. archiveClassifier. set(' ' )
169162
170163 // TODO: This needs reworked so we have one consistent license view, for now the disclaimer is shipped so this should suffice until this is fixed.
171164 it. transform(ApacheLicenseResourceTransformer )
172165 it. transform(ApacheNoticeResourceTransformer )
173166 it. exclude(' DISCLAIMER' , ' license.header' , ' licenses/**' , ' META-INF/NOTICE.md' , ' META-INF/NOTICE' , ' META-INF/NOTICE.md' , ' META-INF/licenses/**' , ' META-INF/LICENSE.md' )
174167
175- mergeServiceFiles()
168+ it . mergeServiceFiles()
176169}
177170
178- tasks. named(' shadowDistZip' ) {
179- enabled = false
180- }
181- tasks. named(' shadowDistTar' ) {
182- enabled = false
171+ TaskProvider<CreateStartScripts > forgeCliStartScripts = tasks. register(' createForgeCliStartScripts' , CreateStartScripts )
172+ forgeCliStartScripts. configure { CreateStartScripts t ->
173+ t. dependsOn jarTask, shadowJarTask
174+ t. outputDir = layout. buildDirectory. dir(' generated-forge-cli-scripts' ). get(). asFile
175+ t. applicationName = ' grails-forge-cli'
176+ t. mainClass = findProperty(' startMainClass' ) as String
177+ t. classpath = files(shadowJarTask)
183178}
184179
185- tasks. named(' distTar' ) {
186- enabled = false
187- }
180+ project. extensions. getByType(DistributionContainer ). configureEach {
181+ it. distributionBaseName. set(' apache-grails' )
182+ it. distributionClassifier. set(' incubating-bin' )
183+ it. contents {
184+ from(shadowJarTask) {
185+ into " lib"
186+ }
188187
189- tasks. register(' copyShadowJar' , Sync ) {
190- from shadowJar. outputs
191- into project. rootProject. layout. buildDirectory. dir(' libs' )
192- rename { String fileName -> ' cli.jar' }
193- }
188+ from(layout. buildDirectory. dir(' build-completion' )) {
189+ into ' bin'
190+ it. filePermissions { permissions ->
191+ permissions. unix(0755 )
192+ }
193+ }
194194
195- tasks. register(' exploded' , Sync ) {
196- dependsOn(' distZip' )
197- from(zipTree(distZip. outputs. files. singleFile))
198- into(project. layout. buildDirectory. dir(' exploded' ))
199- eachFile { FileCopyDetails fcd ->
200- fcd. relativePath = new RelativePath (true , fcd. relativePath. segments. drop(1 ))
201- }
202- onlyIf {
203- distZip. outputs. files. singleFile. exists()
195+ from(forgeCliStartScripts) {
196+ into ' bin'
197+ it. filePermissions { permissions ->
198+ permissions. unix(0755 )
199+ }
200+ }
201+
202+ from(rootProject. layout. projectDirectory. file(' ../LICENSE' )) { it. into ' ' }
203+ from(rootProject. layout. projectDirectory. file(' ../NOTICE' )) { it. into ' ' }
204+ from(rootProject. layout. projectDirectory. file(' ../INSTALL' )) { it. into ' ' }
205+ from(rootProject. layout. projectDirectory. file(' ../DISCLAIMER' )) { it. into ' ' }
204206 }
205207}
206208
207- tasks. register( ' cleanup ' , Delete ) {
208- delete(project . rootProject . layout . buildDirectory . file( ' libs/cli.jar ' ))
209- delete(project . layout . buildDirectory . dir( ' dist ' ) )
209+ def distZipTask = tasks. named( ' distZip ' )
210+ distZipTask . configure {
211+ dependsOn(forgeCliStartScripts, jarTask, shadowJarTask, buildCompletion )
210212}
211-
212- tasks. named(' clean' ) {
213- dependsOn ' cleanup'
213+ tasks. named(' distTar' ). configure {
214+ dependsOn(forgeCliStartScripts, jarTask, shadowJarTask, buildCompletion)
214215}
215-
216- tasks. named(' assemble' ) {
217- dependsOn(' exploded' )
216+ tasks. named(' build' ). configure {
217+ it. dependsOn(distZipTask)
218+ }
219+ tasks. named(' assemble' ). configure {
220+ dependsOn(distZipTask)
221+ }
222+ tasks. named(' installDist' ). configure {
223+ it. dependsOn forgeCliStartScripts, buildCompletion
218224}
219225
220226configurations. configureEach {
0 commit comments