Grails - Profile Inheritance and Publishing Profiles



Description

Profiles can be inherited and published to the Grails Central Repository

Profile Inheritance

You can define profile provisions and dependences, by making changes in build.gradle file. The base profile can be extended as shown below:

dependencies {
    runtime project(':base')
}

Some of the advantages by inheriting from a parent profile are listed below:

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

  • application.yml file is merged from the parent.

  • Dependencies and build.gradle is merged from the parent.

  • Features and CLI commands from the parent profile are shared.

You should ensure that your dependencies are declared in the right order. For instance:

dependencies {
    runtime project(':plugin')
    runtime project(':web')
}

From above instance, it is clear that the skeleton from "plugin" profile is copied first then the "web" profile. Moreover, the "web" profile overrides commands from the "plugin" profile.

Publishing Profiles

Profiles can be published to the Grails Central Repository, for that Grails is having a built-in plugin defined in build.gradle:

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

To use the above plugin for publishing a profile, you have to upload to the source to Github site. Then register your account on Bintray and configure your keys as shown below in build.gradle file:

grailsPublish {
    // TODO: Provide values here
    user = 'user'
    key = 'key'
    githubSlug = 'foo/bar'
    license {
        name = 'Apache-2.0'
    }
    title = "My Profile"
    desc = "Full profile description"
    developers = [johndoe:"John Doe"]
}

Now to publish the profile you have to run following command:

gradle publishProfile

The above command will upload the profile to Bintray, then go to Grails profiles repository and request to include the profile by clicking Include My Package button on Bintray’s interface.

To publish profiles to an internal repository, you need to define the repository in build.gradle file. For instance:

publishing {
    repositories {
        maven {
            credentials {
                username "user_name"
                password "pass_word"
            }

            url "http://username.com/repo"
        }
    }
}

After configuring you can publish your plugin by running the following command:

 gradle publish
Advertisements