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
Related
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')
}
}
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
I would like to change my project from Grails from 3.0.9 to 3.0.10 since latter contains Promise API.
How to do that in IntelliJ?
in the gradle.properties file change
grailsVersion=3.0.10
also in the build.gradle change
buildscript {
ext {
grailsVersion = project.grailsVersion
}
}
You just need to change the grails version in gradle.properties. The gradle build script will pull the required jar files from the grails repo specified in your build file.
In grails 3.0.(1,2,3) the war file exist under the folder 'build/libs'
However, I want to rename the war name with different file suffix, like "app.tar.gz", without the version.
the google result is all about grails 2.x
I put the grails.project.war.file = "target/${appName}.tar.gz" in the file application.groovy under the folder conf but it's useless.
Plz help me, i googled and try to find solution in the source code BuildSettings.groovy, but the it's no use.
As of grails version 3, the build tool is gradle, you would need to change those parameters from your build.gradle file
If you do not want the version as part of your package name, you will need to comment (or remove) the version from build.gradle file
for example, running the following
fhenri#machine:~/project/grails/sample307$ grails -version
| Grails Version: 3.0.7
| Groovy Version: 2.4.4
| JVM Version: 1.8.0_51
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample-0.1.war
After you remove the version from `build.gradle` file
fhenri#machine:~/project/grails/sample307$ grails package
...
fhenri#machine:~/project/grails/sample307$ find . -name *.war
./build/libs/sample.war
Grails uses the war gradle plugin, from the plugin the pattern to make the archive name is [baseName]-[appendix]-[version]-[classifier].[extension], the version already comes from the build.gradle file as generated from grails create-app
each of this can be overwritten in a war closure, for example, an excerpt of the build.gradle could be
version "0.1"
war {
appendix "so-test"
version "1.0"
}
The generated war file will be sample-so-test-1.0.war the version will come from the war closure.
So if you want to keep the mail version properties but do not want to generate the version in your generated war name you can overwritten the property with an empty value
version "0.1"
war {
version ""
}
will generate a war file without the version information, but still you could keep it for you if you want to use it somewhere else.
To package as tar/zip, you can
follow the documentation for grails 3: http://grails.github.io/grails-doc/latest/guide/deployment.html (chapter on TAR/ZIP distribution)
In build.gradle, after applying the gradle war plugin you can do this:
war {
archiveName = "ROOT.war"
}
And a ROOT.war file will be created at build/libs
How do I create a grails war file so that it doesn't have the version number
(e.g. foo-0.1.war)
attached to the end when I execute the 'grails war' command?
In case anybody comes upon this article and is using Grails 1.3.x, the configuration option has changed from grails.war.destFile in Config.groovy to being grails.project.war.file in BuildConfig.groovy.
Also the file name is relative to the project workspace, so it should have a value like:
grails.project.war.file = "target/${appName}.war"
This is according to the latest Grails documentation.
I think you can specify the war name in the war command.
grails war foo.war
Also check the latest Grails documentation for where to set this as a configuration option. See the other answers for details.
From the Grails Documentation, Chapter 17, Deployment
There are also many ways in which you can customise the WAR file that is
created. For example, you can specify
a path (either absolute or relative)
to the command that instructs it where
to place the file and what name to
give it:
grails war /opt/java/tomcat-5.5.24/foobar.war
Alternatively, you can add a line to
Config.groovy that changes the default
location and filename:
grails.war.destFile = "foobar-prod.war"
Of course, any command line argument
that you provide overrides this
setting.
Rolling up the other excellent answers. There are several options:
Explicitly set it on the command line: grails war foo.war
Set the app.version property to empty in application.properties will cause the war to be named foo.war.
Explicitly set the name of the war using the grails.war.destFile property in Config.groovy
Grails 3.x has switched to gradle and uses the war plugin. You can just specify name like this in the build.gradle file:
war {
archiveName 'foo.war'
}
Another way to generate war files without version number is to keep the property, app.version, empty in the application.properties
I am kind of late to the party... but anyway:
I think the reason behind removing the version number is to eliminate the need to rename the war file so it deploys on "correct" context path /appName. If that's the case then a better option is to use a versioned war filename so you can deploy multiple versions at the same time on tomcat using the following naming pattern in grails-app/conf/BuildConfig.groovy:
grails.project.war.file = "target/${appName}##${appVersion}.war"
As explained in http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Parallel_deployment
This method applies to wars in general, not only grails' wars.