There are two steps to follow when adding a new Blade profile:
You’ll learn how to create a profile first.
Creating a New Profile
To create a new Blade profile, follow these steps:
-
To create a new command, create the command and arguments classes extending
BaseCommand
andBaseArgs
, respectively, as described in the Creating Custom Commands article. These classes should reside in the profile module’ssrc/main/java/PACKAGE_NAME
folder. These classes register your command and arguments to Blade CLI. -
To override a default command, follow the same steps outlined here:
- Create a command class
- Create an arguments class
- Define your commands’ fully qualified class names for the service loader
Instead of extending the
BaseCommand
andBaseArgs
, classes, however, extend the command/arguments classes defined for the command you intend to override. Make sure to also set the@Parameters
annotation’scommandNames
argument to the command to override.For example, if you intend to override the default
deploy
command, your arguments class declaration would look like this:@Parameters(commandDescription = "Overridden Deploy Command", commandNames = "deploy") public class OverriddenArgs extends DeployArgs { }
The corresponding command class override would look like this:
public class OverriddenCommand extends BaseCommand<OverriddenArgs> { @Override public void execute() throws Exception { OverriddenArgs args = getArgs(); getBladeCLI().out("OverriddenCommand says " + args.isWatch()); } @Override public Class<OverriddenArgs> getArgsClass() { return OverriddenArgs.class; } }
You can search for the default command/arguments classes here.
-
To associate a command to your new profile, set the
BladeProfile
annotation in your command class:@BladeProfile("myprofile") public class NewCommand extends BaseCommand<NewArgs> { }
The annotation’s parameter should specify the profile you want to associate the command with (e.g.,
myprofile
).
Excellent! You’ve created a new Blade profile and learned how to add new commands or override default commands by leveraging the profile.
You can reference the sample profile project to examine a new command and overridden command’s setup in a custom profile.
Next, you’ll learn how to set your new profile for use in a Liferay Workspace.
Setting a Profile
To set your new Blade profile in a Liferay Workspace, open the
${workspaceDir}/.blade.properties
file and set the profile.name
property to
your profile name:
profile.name=myprofile
This specifies which Blade profile is active and uses its defined commands. The
default setting is gradle
. You can also set this property to maven
out-of-the-box, which is applied for Maven-based workspaces. You can only set
one profile for a workspace.
You can specify the Blade profile for a workspace when initializing it too. This is done by passing the profile name as an argument when creating the workspace:
blade init -P [profile-name] [workspace-name]
For example, if you execute the following command:
blade init -P myprofile my-new-custom-workspace
Your my-new-custom-workspace
has the following properties set in its
${workspaceDir}/.blade.properties
file:
liferay.version.default=7.2
profile.name=myprofile
Awesome! You’ve set your new Blade profile!