(Quick Reference)

6 Application Profiles

Version: 7.0.0-SNAPSHOT

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, and 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 Maven 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 Maven central repository, you must specify Maven central in the file as well:

grails {
  profiles {
    repositories {
      myRepo {
        url = "https://foo.com/repo"
        snapshotsEnabled = true
      }
      mavenCentral()
    }
  }
}
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 = "https://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 simplify this process, you can define defaults for that profile in your USER_HOME/.grails/settings.groovy file:

grails {
  profiles {
    myprofile {
      groupId = "com.mycompany.grails.profiles"
      version = "1.0.0"
    }
    repositories {
      ...
    }
  }
}

With the defaults set, the following command will use the defined group ID and version:

$ grails create-app myapp --profile=myprofile

6.1 Standard Profiles

Grails provides a set of standard application profiles that serve as foundational templates for generating various types of projects. These profiles encapsulate specific commands, templates, plugins, and configurations tailored to different development needs, allowing developers to quickly generate applications or plugins with predefined structures. The standard profiles are resolved from Maven Central.

Standard profiles include base, web, rest-api, plugin, web-plugin, rest-api-plugin and profile. Most extend from other profiles to promote reusability and consistency.

Available profiles can be listed, when not inside a Grails' project directory:

$ grails list-profiles
| Available Profiles
--------------------
* base - The base profile extended by other profiles
* plugin - Profile for plugins designed to work across all profiles
* profile - A profile for creating new Grails profiles
* rest-api - Profile for REST API applications
* rest-api-plugin - Profile for REST API plugins
* web - Profile for Web applications
* web-plugin - Profile for Plugins designed for Web applications

The base profile acts as the foundational layer extended by most other profiles, providing essential skeleton directories, core dependencies, and basic commands that form the backbone of any Grails project. It ensures a standardized starting point without imposing specific application paradigms.

For application development, the web profile is the default when creating a new Grails app, optimized for full-stack web applications with features like GSP views, controllers, and the asset pipeline. The rest-api profile, on the other hand, targets REST API-centric projects, emphasizing RESTful endpoints, JSON handling, and configurations suitable for backend services.

The plugin profile is designed for creating reusable plugins that can integrate across various Grails applications. Similarly, the web-plugin profile focuses on plugins tailored specifically for web applications, inheriting from the web and plugin profiles. The rest-api-plugin profile is specialized for developing plugins that provide REST API functionality, inheriting from the rest-api and plugin profiles, enabling the creation of modular, reusable components focused on API endpoints.

Lastly, the profile profile is intended for developers creating custom profiles.

These profiles collectively enable flexible project generation while maintaining Grails' convention-over-configuration philosophy.

6.1.1 Web Profile

To create an application using the web profile:

grails create-app myapp

web is the default profile. The above statement is equivalent to:

grails create-app myapp --profile=web

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info web

You will see an output similar to:

Profile: web
--------------------
Profile for Web applications

Provided Commands:
--------------------
* create-controller - Creates a controller
* create-integration-test - Creates an integration test
* create-interceptor - Creates an interceptor
* create-service - Creates a Service
* create-taglib - Creates a Tag Library
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates an Application Command
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell

Provided Features:
--------------------
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project

6.1.2 REST API Profile

To create an application using the rest-api profile:

grails create-app myapp --profile=rest-api

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info rest-api

You will see an output similar to:

Profile: rest-api
--------------------
Profile for REST API applications

Provided Commands:
--------------------
* create-controller - Creates a controller
* create-domain-resource - Creates a domain class that represents a resource
* create-functional-test - Creates an functional test
* create-integration-test - Creates an integration test
* create-interceptor - Creates an interceptor
* create-restful-controller - Creates a REST controller
* create-service - Creates a Service
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates an Application Command
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell
* generate-all - Generates a controller that performs REST operations
* generate-functional-test - Generates a functional test for a controller that performs REST operations
* generate-views - Generates a controller that performs REST operations
* generate-unit-test - Generates a unit test for a controller that performs REST operations
* generate-controller - Generates a controller that performs REST operations

Provided Features:
--------------------
* security - Adds Spring Security REST to the project
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project

6.1.3 Plugin Profile

To create an application using the plugin profile:

grails create-plugin myplugin

The above statement is equivalent to:

grails create-app myplugin --profile=plugin

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info plugin

You will see an output similar to:

Profile: plugin
--------------------
Profile for plugins designed to work across all profiles

Provided Commands:
--------------------
* install - Installs a plugin into the local Maven cache
* package-plugin - Packages the plugin into a JAR file
* publish-plugin - Publishes the plugin to the Grails central repository
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates an Application Command
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell

Provided Features:
--------------------
* asset-pipeline-plugin - Adds Asset Pipeline to a Grails Plugin for packaging
* maven-publish - Publish Artifacts to Maven Central
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project

6.1.4 Web Plugin Profile

To create an application using the web-plugin profile:

grails create-web-plugin myplugin

The above statement is equivalent to:

grails create-app myplugin --profile=web-plugin

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info web-plugin

You will see an output similar to:

Profile: web-plugin
--------------------
Profile for Plugins designed for Web applications

Provided Commands:
--------------------
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* create-controller - Creates a controller
* create-integration-test - Creates an integration test
* create-interceptor - Creates an interceptor
* create-service - Creates a Service
* create-taglib - Creates a Tag Library
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates an Application Command
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell
* install - Installs a plugin into the local Maven cache
* package-plugin - Packages the plugin into a JAR file
* publish-plugin - Publishes the plugin to the Grails central repository

Provided Features:
--------------------
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project
* asset-pipeline-plugin - Adds Asset Pipeline to a Grails Plugin for packaging
* maven-publish - Publish Artifacts to Maven Central

6.1.5 REST API Plugin Profile

To create an application using the rest-api-plugin profile:

grails create-app myplugin --profile=rest-api-plugin

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info rest-api-plugin

You will see an output similar to:

Profile: rest-api-plugin
--------------------
Profile for REST API plugins

Provided Commands:
--------------------
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* install - Installs a plugin into the local Maven cache
* package-plugin - Packages the plugin into a JAR file
* publish-plugin - Publishes the plugin to the Grails central repository
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates an Application Command
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell
* create-controller - Creates a controller
* create-domain-resource - Creates a domain class that represents a resource
* create-functional-test - Creates an functional test
* create-integration-test - Creates an integration test
* create-interceptor - Creates an interceptor
* create-restful-controller - Creates a REST controller
* create-service - Creates a Service
* generate-all - Generates a controller that performs REST operations
* generate-controller - Generates a controller that performs REST operations
* generate-functional-test - Generates a functional test for a controller that performs REST operations
* generate-views - Generates a controller that performs REST operations
* generate-unit-test - Generates a unit test for a controller that performs REST operations

Provided Features:
--------------------
* asset-pipeline-plugin - Adds Asset Pipeline to a Grails Plugin for packaging
* maven-publish - Publish Artifacts to Maven Central
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project
* security - Adds Spring Security REST to the project

6.1.6 Profile Profile

To create an application using the profile profile:

grails create-profile myprofile

The above statement is equivalent to:

grails create-app myprofile --profile=profile

To get information about the profile and available features, when not inside a Grails' project directory:

grails profile-info profile

You will see an output similar to:

Profile: profile
--------------------
A profile for creating new Grails profiles

Provided Commands:
--------------------
* install - Installs a profile into the local Maven cache
* help - Prints help information for a specific command
* url-mappings-report - Prints out a report of the project's URL mappings
* open - Opens a file in the project
* gradle - Allows running of Gradle tasks
* clean - Cleans a Grails application's compiled sources
* compile - Compiles a Grails application
* create-command - Creates a new command for the profile
* create-domain-class - Creates a Domain Class
* create-unit-test - Creates a unit test
* assemble - Creates a JAR or WAR archive for production deployment
* test-app - Runs the applications tests
* run-command - Executes Grails commands
* console - Runs the Grails interactive console
* run-script - Executes Groovy scripts in a Grails context
* stop-app - Stops the running Grails application
* stats - Prints statistics about the project
* plugin-info - Prints information about the given plugin
* create-script - Creates a Grails script
* bug-report - Creates a zip file that can be attached to issue reports for the current project
* run-app - Runs a Grails application
* dependency-report - Prints out the Grails application's dependencies
* list-plugins - Lists available plugins from the Plugin Repository
* shell - Runs the Grails interactive shell
* create-creator-command - Creates a new create-* command for the profile
* create-feature - Creates a new profile feature
* create-generator-command - Creates a new generate-* command for the profile
* create-template - Creates a new template for the profile
* create-gradle-command - Creates a new command that invokes Gradle for the profile

Provided Features:
--------------------
* asset-pipeline - Adds Asset Pipeline to a Grails project
* events - Adds support for the Grails EventBus abstraction
* geb2 - Adds Geb dependencies to run functional tests.
* gsp - Adds support for GSP to the project
* hibernate5 - Adds GORM for Hibernate 5 to the project
* json-views - Adds support for JSON Views to the project
* less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
* markup-views - Adds support for Markup Views to the project
* mongodb - Adds GORM for MongoDB to the project
* neo4j - Adds GORM for Neo4j to the project
* rx-mongodb - Adds RxGORM for MongoDB to the project

6.2 Creating Profiles

The idea behind creating a new profile is that you can setup a default set of commands and plugins that are tailored to a particular technology or organisation.

To create a new profile you can use the create-profile command which will create a new empty profile that extends the base profile:

$ grails create-profile mycompany

The above command will create a new profile in the "mycompany" directory where the command is executed. If you start interactive mode within the directory you will get a set of commands for creating profiles:

$ cd mycompany
$ grails
| Enter a command name to run. Use TAB for completion:
grails>

create-command      create-creator-command      create-feature      create-generator-command    create-gradle-command   create-template

The commands are as follows:

  • create-command - creates a new command that will be available from the Grails CLI when the profile is used

  • create-creator-command - creates a command available to the CLI that renders a template (Example: create-controller)

  • create-generator-command - creates a command available to the CLI that renders a template based on a domain class (Example: generate-controller)

  • create-feature - creates a feature that can be used with this profile

  • create-gradle-command - creates a CLI command that can invoke gradle

  • create-template - creates a template that can be rendered by a command

To customize the dependencies for your profile you can specify additional dependencies in profile.yml.

Below is an example profile.yml file:

features:
    defaults:
        - hibernate
        - asset-pipeline
build:
    plugins:
        - org.apache.grails.gradle.grails-web
    excludes:
        - org.grails.grails-core
dependencies:
    - scope: compile
      coords: "org.mycompany:myplugin:1.0.1"
    - scope: testCompile
      coords: org.spockframework:spock-core
      excludes:
        - group: org.codehaus.groovy
          module: groovy-all

With the above configuration in place you can publish the profile to your local repository with gradle install:

$ gradle install

Your profile is now usable with the create-app command:

$ grails create-app myapp --profile mycompany

With the above command the application will be created with the "mycompany" profile which includes an additional dependency on the "myplugin" plugin and also includes the "hibernate" and "asset-pipeline" features (more on features later).

Note that if you customize the dependency coordinates of the profile (group, version etc.) then you may need to use the fully qualified coordinates to create an application:

$ grails create-app myapp --profile com.mycompany:mycompany:1.0.1

6.3 Profile Inheritance

One profile can extend one or many different parent profiles. To define profile inheritance you can modify the build.gradle of a profile and define the profile dependences. For example typically you want to extend the base profile:

dependencies {
    profileRuntimeApi "org.apache.grails.profiles:base:{version}"
}

By inheriting from a parent profile you get the following benefits:

  • When the create-app command is executed the parent profile’s skeleton is copied first

  • Dependencies and build.gradle is merged from the parent(s)

  • The application.yml file is merged from the parent(s)

  • CLI commands from the parent profile are inherited

  • Features from the parent profile are inherited

To define the order of inheritance ensure that your dependencies are declared in the correct order. For example:

dependencies {
    profileRuntimeApi "org.apache.grails.profiles:plugin:$baseProfileVersion"
    profileRuntimeApi "org.apache.grails.profiles:web:$baseProfileVersion"
}

In the above snippet the skeleton from the "plugin" profile is copied first, followed by the "web" profile. In addition, the "web" profile overrides commands from the "plugin" profile, whilst if the dependency order was reversed the "plugin" profile would override the "web" profile.

6.4 Publishing Profiles

Publishing Profiles

To mark a profile project for publishing, you need to apply the grails-profile-publish plugin:

apply plugin: "org.apache.grails.gradle.grails-publish-profile"

To publish a profile using this plugin to the Grails central repository first upload the source to Github (closed source profiles will not be accepted). Then register for an account on Maven Central and configure your keys as follows in the profile’s build.gradle file:

grailsPublish {
        githubSlug = 'foo/bar'
        license {
            name = 'Apache-2.0'
        }
        title = 'My profile title'
        desc = 'My profile description'
        developers = [johndoe: 'John Doe']
    }
The githubSlug argument should point to the path to your Github repository. For example if your repository is located at https://github.com/apache/grails-core then your githubSlug is apache/grails-core

Environment variables control where the profile is published. By default, this plugin will publish to the specified MAVEN_PUBLISH instance for snapshots, and NEXUS_PUBLISH for releases. To change the snapshot publish behavior, set snapshotRepoType to PublishType.NEXUS_PUBLISH. To change the release publish behavior, set releaseRepoType to PublishType.MAVEN_PUBLISH.

The credentials and connection url must be specified as a project property or an environment variable.

MAVEN_PUBLISH Environment Variables are:

MAVEN_PUBLISH_USERNAME
MAVEN_PUBLISH_PASSWORD
MAVEN_PUBLISH_URL

NEXUS_PUBLISH Environment Variables are:

NEXUS_PUBLISH_USERNAME
NEXUS_PUBLISH_PASSWORD
NEXUS_PUBLISH_URL
NEXUS_PUBLISH_SNAPSHOT_URL
NEXUS_PUBLISH_STAGING_PROFILE_ID

By default, the release or snapshot state is determined by the project.version or projectVersion gradle property. To override this behavior, use the environment variable GRAILS_PUBLISH_RELEASE to decide if it’s a release or snapshot.

With these environment variables in place you can run gradle publish to publish your profile:

$ gradle publish

The profile will be uploaded to the specified location based on whether the version is a snapshot or release.

6.5 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:

/web
    commands/
        create-controller.yml
        run-app.groovy
        ...
    features/
        asset-pipeline/
            skeleton
            feature.yml
    skeleton/
        grails-app/
            controllers/
            ...
        build.gradle
    templates/
        artifacts/
            Controller.groovy
    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:

repositories:
    - "https://repo1.maven.org/maven2"

2) build.repositories

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

build:
    repositories:
        - "https://repo1.maven.org/maven2"

3) build.plugins

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

build:
    plugins:
        - eclipse
        - idea
        - org.grails.grails-core

4) build.excludes

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

build:
    excludes:
        - 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:

dependencies:
    - scope: excludes
      coords: "org.grails:hibernate:*"
    - scope: build
      coords: "org.grails:grails-gradle-plugin:$grailsVersion"
    - scope: compile
      coords: "org.springframework.boot:spring-boot-starter-logging"
    - scope: compile
      coords: "org.springframework.boot:spring-boot-autoconfigure"
Excluding Transitive Dependencies

To exclude transitive dependencies, define excludes key with a List of transitive dependencies Map of the dependency group, module, classifier, and extension as:

dependencies:
    - scope: testCompile
      coords: org.spockframework:spock-core
      excludes:
        - group: org.codehaus.groovy
          module: groovy-all

6) features.defaults

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

features:
    defaults:
        - hibernate
        - asset-pipeline

7) skeleton.excludes

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

skeleton:
    excludes:
        - gradlew
        - gradlew.bat
        - 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.

skeleton:
    parent:
        target: app

9) skeleton.binaryExtensions

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

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

skeleton:
    executable:
      - "**/gradlew*"
      - "**/grailsw*"

11) instructions

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

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 by collecting all dependency information defined in the profile.yml files, resulting in a complete list of 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.

6.6 Creating Profile Commands

A profile can define new commands that apply only to that profile using YAML or Groovy scripts. Below is an example of the create-controller command defined in YAML:

description:
    - Creates a controller
    - usage: 'create-controller <<controller name>>'
    - completer: org.grails.cli.interactive.completers.DomainClassCompleter
    - argument: "Controller Name"
      description: "The name of the controller"
steps:
 - command: render
   template: templates/artifacts/Controller.groovy
   destination: grails-app/controllers/`artifact.package.path`/`artifact.name`Controller.groovy
 - command: render
   template: templates/testing/Controller.groovy
   destination: src/test/groovy/`artifact.package.path`/`artifact.name`ControllerSpec.groovy
 - command: mkdir
   location: grails-app/views/`artifact.propertyName`

Commands defined in YAML must define one or many steps. Each step is a command in itself. The available step types are:

  • render - To render a template to a given destination (as seen in the previous example)

  • mkdir - To make a directory specified by the location parameter

  • execute - To execute a command specified by the class parameter. Must be a class that implements the Command interface.

  • gradle - To execute one or many Gradle tasks specified by the tasks parameter.

For example to invoke a Gradle task, you can define the following YAML:

description: Creates a WAR file for deployment to a container (like Tomcat)
minArguments: 0
usage: |
 war
steps:
 - command: gradle
   tasks:
     - war

If you need more flexibility than what the declarative YAML approach provides you can create Groovy script commands. Each Command script is extends from the GroovyScriptCommand class and hence has all of the methods of that class available to it.

The following is an example of the create-script command written in Groovy:

description( "Creates a Grails script" ) {
  usage "grails create-script <<SCRIPT NAME>>"
  argument name:'Script Name', description:"The name of the script to create"
  flag name:'force', description:"Whether to overwrite existing files"
}

def scriptName = args[0]
def model = model(scriptName)
def overwrite = flag('force') ? true : false

render  template: template('artifacts/Script.groovy'),
        destination: file("src/main/scripts/${model.lowerCaseName}.groovy"),
        model: model,
        overwrite: overwrite

For more information on creating CLI commands see the section on creating custom scripts in the Command Line section of the user guide.

6.7 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:

$ grails create-feature myfeature

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

description: Description of the feature
# customize versions here
# dependencies:
#   - scope: compile
#     coords: "org.grails.plugins:myplugin2:1.0"
#

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

description: Adds Asset Pipeline to a Grails project
build:
    plugins:
        - asset-pipeline
dependencies:
    - scope: build
      coords: 'cloud.wondrify:asset-pipeline-gradle'
    - scope: runtime
      coords: "org.grails.plugins:asset-pipeline"

The structure of a feature is as follows:

FEATURE_DIR
    feature.yml
    skeleton/
        grails-app/
            conf/
                application.yml
        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:

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