forked from grails/grails-doc
/
buildCustomising.gdoc
68 lines (57 loc) · 5.78 KB
/
buildCustomising.gdoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Grails is most definitely an opinionated framework and it prefers convention to configuration, but this doesn't mean you _can't_ configure it. In this section, we look at how you can influence and modify the standard Grails build.
h3. The defaults
The core of the Grails build configuration is the @grails.util.BuildSettings@ class, which contains quite a bit of useful information. It controls where classes are compiled to, what dependencies the application has, and other such settings.
Here is a selection of the configuration options and their default values:
{table}
*Property* | *Config option* | *Default value*
grailsWorkDir | grails.work.dir | $USER_HOME/.grails/<grailsVersion>
projectWorkDir | grails.project.work.dir | <grailsWorkDir>/projects/<baseDirName>
classesDir | grails.project.class.dir | <projectWorkDir>/classes
testClassesDir | grails.project.test.class.dir | <projectWorkDir>/test-classes
testReportsDir | grails.project.test.reports.dir | <projectWorkDir>/test/reports
resourcesDir | grails.project.resource.dir | <projectWorkDir>/resources
projectPluginsDir | grails.project.plugins.dir | <projectWorkDir>/plugins
globalPluginsDir | grails.global.plugins.dir | <grailsWorkDir>/global-plugins
verboseCompile | grails.project.compile.verbose | @false@
{table}
The @BuildSettings@ class has some other properties too, but they should be treated as read-only:
{table}
*Property* | *Description*
baseDir | The location of the project.
userHome | The user's home directory.
grailsHome | The location of the Grails installation in use (may be @null@).
grailsVersion | The version of Grails being used by the project.
grailsEnv | The current Grails environment.
config | The configuration settings defined in the project's @BuildConfig.groovy@ file. Access properties in the same way as you access runtime settings: @grailsSettings.config.foo.bar.hello@.
compileDependencies | A list of compile-time project dependencies as @File@ instances.
testDependencies | A list of test-time project dependencies as @File@ instances.
runtimeDependencies | A list of runtime-time project dependencies as @File@ instances.
{table}
Of course, these properties aren't much good if you can't get hold of them. Fortunately that's easy to do: an instance of @BuildSettings@ is available to your scripts as the @grailsSettings@ script variable. You can also access it from your code by using the @grails.util.BuildSettingsHolder@ class, but this isn't recommended.
h3. Overriding the defaults
All of the properties in the first table can be overridden by a system property or a configuration option - simply use the "config option" name. For example, to change the project working directory, you could either run this command:
{code}
grails -Dgrails.project.work.dir=work compile
{code}
or add this option to your @grails-app/conf/BuildConfig.groovy@ file:
{code}
grails.project.work.dir = "work"
{code}
Note that the default values take account of the property values they depend on, so setting the project working directory like this would also relocate the compiled classes, test classes, resources, and plugins.
What happens if you use both a system property and a configuration option? Then the system property wins because it takes precedence over the @BuildConfig.groovy@ file, which in turn takes precedence over the default values.
The @BuildConfig.groovy@ file is a sibling of @grails-app/conf/Config.groovy@ - the former contains options that only affect the build, whereas the latter contains those that affect the application at runtime. It's not limited to the options in the first table either: you will find build configuration options dotted around the documentation, such as ones for specifying the port that the embedded servlet container runs on or for determining what files get packaged in the WAR file.
h3. Available build settings
{table}
Name | Description
grails.server.port.http | Port to run the embedded servlet container on ("run-app" and "run-war"). Integer.
grails.server.port.https | Port to run the embedded servlet container on for HTTPS ("run-app \-\-https" and "run-war \-\-https"). Integer.
grails.config.base.webXml | Path to a custom web.xml file to use for the application (alternative to using the web.xml template).
grails.compiler.dependencies | Legacy approach to adding extra dependencies to the compiler classpath. Set it to a closure containing "fileset()" entries. These entries will be processed by an @AntBuilder@ so the syntax is the Groovy form of the corresponding XML elements in an Ant build file, e.g. @fileset(dir: "$basedir/lib", include: "\*\*/\*.class)@.
grails.testing.patterns | A list of Ant path patterns that let you control which files are included in the tests. The patterns should not include the test case suffix, which is set by the next property.
grails.testing.nameSuffix | By default, tests are assumed to have a suffix of "Tests". You can change it to anything you like but setting this option. For example, another common suffix is "Test".
grails.project.war.file | A string containing the file path of the generated WAR file, along with its full name (include extension). For example, "target/my-app.war".
grails.war.dependencies | A closure containing "fileset()" entries that allows you complete control over what goes in the WAR's "WEB-INF/lib" directory.
grails.war.copyToWebApp | A closure containing "fileset()" entries that allows you complete control over what goes in the root of the WAR. It overrides the default behaviour of including everything under "web-app".
grails.war.resources | A closure that takes the location of the staging directory as its first argument. You can use any Ant tasks to do anything you like. It is typically used to remove files from the staging directory before that directory is jar'd up into a WAR.
grails.project.web.xml | The location to generate Grails' web.xml to
{table}