Add additional files to Grails WAR file - grails

I wanna add additional files, respectively test data file, to the generated WAR file. How can I modify the build.gradle to reach this goal? I have already tried to change the war task, e.g.
war {
from "testdata"
}
but no files were added to the war file. GRAILS 3.1.8 is used.

Here is example code - we use it to copy generated docs to war:
//copy documnetation to war if exist
war {
from('build/docs/manual') {
include '**/*'
into('docs')
}
}

Related

How to exclude grails plugin jar from war file

Grails 3.2.5. Build.gradle has mail plugin:
compile "org.grails.plugins:mail:2.0.0.RC6"
In deploying a war to production I need to remove javax.mail-1.5.6.jar from WEB-INF/lib since that jar must be in the Tomcat lib when using a JNDI mail resource. So how do I keep the mail plugin but remove the offending jar file from the war? I knew how to do this in Grails 2.x. Via the gradle war task in build.gradle I have tried to exclude the file (doesn't work - the jar drifts in from a plugin somehow), and have tried to filter the file out. When I build the war I get two files - "app-0.1.war" and "app-0.1.war.original". The "original" file has the WEB-INF/lib/javax.mail jar filtered out, but the real, complete war still has it.
So how do I prevent that plugin jar from getting into the war file? Thanks.
One way to do it is with something like this:
war {
rootSpec.exclude '**/javax.mail*.jar'
}
(you may need to adjust depending on whether or not you want to also exclude the javax.mail-api jar file along with the javax.mail jar)
See https://github.com/jeffbrown/excludejar/blob/67734ac0c65cdbead468f1e65bcfc29041cd2279/build.gradle#L70-L72

Create war file in grails using GGTS

I have done a small application in Grails, and now I need to generate a war file to test it on server. I generated a war using command grails:war. It has generated the file but named it as myapp-01.war. I don't want this, I need a war where the file name should be same as the project; like myapp.war
Try:
grails war myapp.war
Additional options: http://docs.grails.org/3.1.1/ref/Command%20Line/war.html

overwrite app-convert.properties file in highchart-export-web war

I have used highchart-export-web war in my project. I want to change app-convert.properties file of the war on runtime. (while extracting war to deploy folder. )

Create Grails 3 WAR without version number

In Grails 2 we could define WAR filename like this:
grails.project.war.file = "target/${appName}.war"
How can I override the war filename in Grails 3?
Thanks Jeff.
I have added line like thisin build.gradle:
war {
archiveName "${war.baseName}.war"
}
In build.gradle you can do something like war.archiveName='jeff.war'. See https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.War.html#org.gradle.api.tasks.bundling.War%3aarchiveName.
A more detailed answer: Add this to wrapper task in build.gradle so it creates different war file name based on each environment.
war.archiveName="${war.baseName}_${grails.util.Environment.current.name}.war"
Then create war file like this.
grails -Dgrails.env=staging war

Excude all the unnecessary jar from war file

I am a grails programmer and I want to remove the unnecessary jar files that are included in the war file. There are so many unnecessary jar files included in the war file. Is there any quick solution to do so? Also can you mention the jar files which are necessary to make and run the simple grails war.
You can exclude unnecessary jar from war by adding following lines in BuildConfig.groovy.
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/jarFileName.jar")
}
Example : Removing hibernate core
grails.war.resources = { stagingDir ->
delete(file:"${stagingDir}/WEB-INF/lib/hibernate-core-3.3.1.GA.jar")
}

Resources