6 Application Profiles
When you create a Grails application with the create-app command by default the "web" profile is used:
grails create-app myapp
You can specify a different profile with the profile argument:
grails create-app myapp --profile=rest-api
Profiles encapsulate the project commands, templates and plugins that are designed to work for a given profile. The source for the profiles can be found on Github, whilst the profiles themselves are published as JAR files to the Grails central repository.
To find out what profiles are available use the list-profiles command:
$ grails list-profiles
For more information on a particular profile use the profile-info command:
$ grails profile-info rest-api
Commands such as profile-info or list-profiles are not available when you invoke the Grails CLI inside a grails project. |
Profile Repositories
By default Grails will resolve profiles from the Grails central repository. However, you can override what repositories will be searched by specifying repositories in the USER_HOME/.grails/settings.groovy
file.
If you want profiles to be resolved with a custom repository in addition to the Grails central repository, you must specify Grails central in the file as well:
grails {
profiles {
repositories {
myRepo {
url = "http://foo.com/repo"
snapshotsEnabled = true
}
grailsCentral {
url = "https://repo.grails.org/grails/core"
snapshotsEnabled = true
}
}
}
}
Grails uses Aether to resolve profiles, as a Gradle instance is not yet available when the create-app command is executed. This means that you can also define repositories and more advanced configuration (proxies, authentication etc.) in your USER_HOME/.m2/settings.xml file if you wish. |
It is also possible to store simple credentials for profile repositories directly in the USER_HOME/.grails/settings.groovy
file.
grails {
profiles {
repositories {
myRepo {
url = "http://foo.com/repo"
snapshotsEnabled = true
username = "user"
password = "pass"
}
...
}
}
}
Profile Defaults
To create an application that uses a custom profile, you must specify the full artifact.
$ grails create-app myapp --profile=com.mycompany.grails.profiles:myprofile:1.0.0
To make this process easier, you can define defaults for a given profile in the USER_HOME/.grails/settings.groovy
file.
grails {
profiles {
myprofile {
groupId = "com.mycompany.grails.profiles"
version = "1.0.0"
}
repositories {
...
}
}
}
With the default values specified, the command to create an application using that profile becomes:
$ grails create-app myapp --profile=myprofile