6.4 Understanding Profiles

A profile is a simple directory that contains a profile.yml file and directories containing the "commands", "skeleton" and "templates" defined by the profile. Example:

  1. /web
  2. commands/
  3. create-controller.yml
  4. run-app.groovy
  5. ...
  6. features/
  7. asset-pipeline/
  8. skeleton
  9. feature.yml
  10. skeleton/
  11. grails-app/
  12. controllers/
  13. ...
  14. build.gradle
  15. templates/
  16. artifacts/
  17. Controller.groovy
  18. profile.yml

The above example is a snippet of structure of the 'web' profile. The profile.yml file is used to describe the profile and control how the build is configured.

Understanding the profile.yml descriptor

The profile.yml can contain the following child elements.

1) repositories

A list of Maven repositories to include in the generated build. Example:

  1. repositories:
  2. - "https://repo.grails.org/grails/core"

2) build.repositories

A list of Maven repositories to include in the buildscript section of the generated build. Example:

  1. build:
  2. repositories:
  3. - "https://repo.grails.org/grails/core"

3) build.plugins

A list of Gradle plugins to configure in the generated build. Example:

  1. build:
  2. plugins:
  3. - eclipse
  4. - idea
  5. - org.grails.grails-core

4) build.excludes

A list of Gradle plugins to exclude from being inherited from the parent profile:

  1. build:
  2. excludes:
  3. - org.grails.grails-core

5) dependencies

A map of scopes and dependencies to configure. The excludes scope can be used to exclude from the parent profile. Example:

  1. dependencies:
  2. excludes:
  3. - "org.grails:hibernate:*"
  4. build:
  5. - "org.grails:grails-gradle-plugin:$grailsVersion"
  6. compile:
  7. - "org.springframework.boot:spring-boot-starter-logging"
  8. - "org.springframework.boot:spring-boot-autoconfigure"

6) features.defaults

A default list of features to use if no explicit features are specified.

  1. features:
  2. defaults:
  3. - hibernate
  4. - asset-pipeline

7) skeleton.excludes

A list of files to exclude from parent profile’s skeletons (supports wildcards).

  1. skeleton:
  2. excludes:
  3. - gradlew
  4. - gradlew.bat
  5. - gradle/

8) skeleton.parent.target

The target folder that parent profile’s skeleton should be copied into. This can be used to create multi-project builds.

  1. skeleton:
  2. parent:
  3. target: app

9) skeleton.binaryExtensions

Which file extensions should be copied from the profile as binary. Inherited and combined from parent profiles.

  1. skeleton:
  2. binaryExtensions: [exe, zip]

10) skeleton.executable

File patterns that should be marked as executable in the resulting application. Inherited and combined from parent profiles. The patterns are parsed with Ant.

  1. skeleton:
  2. executable:
  3. - "**/gradlew*"
  4. - "**/grailsw*"

11) instructions

Text to be displayed to the user after the application is created

  1. instructions: Here are some instructions

What happens when a profile is used?

When the create-app command runs it takes the skeleton of the parent profiles and copies the skeletons into a new project structure.

The build.gradle file is generated is result of obtaining all of the dependency information defined in the profile.yml files and produces the required dependencies.

The command will also merge any build.gradle files defined within a profile and its parent profiles.

The grails-app/conf/application.yml file is also merged into a single YAML file taking into account the profile and all of the parent profiles.