6.6 Creating Profile Features

A Profile feature is a shareable set of templates and dependencies that may span multiple profiles. Typically you create a base profile that has multiple features and child profiles that inherit from the parent and hence can use the features available from the parent.

To create a feature use the create-feature command from the root directory of your profile:

  1. $ grails create-feature myfeature

This will create a myfeature/feature.yml file that looks like the following:

  1. description: Description of the feature
  2. # customize versions here
  3. # dependencies:
  4. # compile:
  5. # - "org.grails.plugins:myplugin2:1.0"
  6. #

As a more concrete example. The following is the feature.yml file from the "asset-pipeline" feature:

  1. description: Adds Asset Pipeline to a Grails project
  2. build:
  3. plugins:
  4. - asset-pipeline
  5. dependencies:
  6. build:
  7. - 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
  8. runtime:
  9. - "org.grails.plugins:asset-pipeline"

The structure of a feature is as follows:

  1. FEATURE_DIR
  2. feature.yml
  3. skeleton/
  4. grails-app/
  5. conf/
  6. application.yml
  7. build.gradle

The contents of the skeleton get copied into the application tree, whilst the application.yml and build.gradle get merged with their respective counterparts in the profile by used.

With the feature.yml you can define additional dependencies. This allows users to create applications with optional features. For example:

  1. $ grails create-app myapp --profile myprofile --features myfeature,hibernate

The above example will create a new application using your new feature and the "hibernate" feature.