6 Application Profiles

When you create a Grails application with the create-app command by default the "web" profile is used:

  1. grails create-app myapp

You can specify a different profile with the profile argument:

  1. 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:

  1. $ grails list-profiles

For more information on a particular profile use the profile-info command:

  1. $ 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:

  1. grails {
  2. profiles {
  3. repositories {
  4. myRepo {
  5. url = "http://foo.com/repo"
  6. snapshotsEnabled = true
  7. }
  8. grailsCentral {
  9. url = "https://repo.grails.org/grails/core"
  10. snapshotsEnabled = true
  11. }
  12. }
  13. }
  14. }
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.

  1. grails {
  2. profiles {
  3. repositories {
  4. myRepo {
  5. url = "http://foo.com/repo"
  6. snapshotsEnabled = true
  7. username = "user"
  8. password = "pass"
  9. }
  10. ...
  11. }
  12. }
  13. }

Profile Defaults

To create an application that uses a custom profile, you must specify the full artifact.

  1. $ 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.

  1. grails {
  2. profiles {
  3. myprofile {
  4. groupId = "com.mycompany.grails.profiles"
  5. version = "1.0.0"
  6. }
  7. repositories {
  8. ...
  9. }
  10. }
  11. }

With the default values specified, the command to create an application using that profile becomes:

  1. $ grails create-app myapp --profile=myprofile