Project

Contents

Project

Project

By projects, we generally refer to the set of code and configuration required to build applications or libraries for XP. Projects are commonly hosted in a Git repo and need to follow a set of principles to work with Enonic XP. Each project is associated with a sandbox to be run in.

All project commands should be run from the project root folder.

Command list is available by running following command:

$ enonic project

Manage XP development projects

USAGE:
   Enonic CLI project command [command options] [arguments...]

COMMANDS:
     create             Create new project
     sandbox, sbox, sb  Set the default sandbox associated with the current project
     clean              Clean current project
     build              Build current project
     deploy             Deploy current project to a sandbox
     install, i         Build current project and install it to Enonic XP
     shell              Creates a new shell with project environment variables
     env                Exports project environment variables as string to be used in any third-party shell
     gradle             Run arbitrary gradle task in current project

OPTIONS:
   --help, -h  show help

Create

Navigate to the folder you wish to place your project in and run the following command:

$ enonic project create [name] [-n <value>] [-b <value>] [-c <value>] [-d <value>] [-r <value>] [-v <value>]

Follow wizard instructions that will set everything up for you.

Options:

Option Description

name

project name. E.g. com.example.myapp. Can also be specified using --name flag

-n, --name

project name. Overrides [name] argument if specified

-r, --repo,
--repository

repository path. Format: <enonic repo> or <organisation>/<repo> on github or <full repo url>

-b, --branch

repository branch to use. master is used if none specified

-c, --checkout

commit hash to use (mutually exclusive with branch option, used if both are present)

-d, --dest,
--destination

destination folder name. Defaults to last word of the project name, i.e. myapp

-v, --ver, --version

version number to assign to new project. Default value 1.0.0-SNAPSHOT

name, repository, destination and version params are sufficient to create a project without a wizard allowing it to be used in script files.
Example creating 'myProject' project in 'myFolder' folder from vanilla starter and setting '1.0.0-SNAPSHOT' version:
$ enonic project create myProject -d myFolder -r starter-vanilla -v 1.0.0-SHAPSHOT
Same example but providing name as a flag:
$ enonic project create -n myProject -d myFolder -r starter-vanilla -v 1.0.0-SHAPSHOT

Sandbox

Project create will configure the default sandbox for your project. To change it later run this command inside the project folder:

$ enonic project sandbox [name]

Options:

Option Description

name

sandbox name

If name is not provided or does not exist, you will be asked for it.
Example setting 'myOtherBox' as default sandbox for current project:
$ enonic project sandbox myOtherBox

Build

You can build your project by running following command inside the project folder:

$ enonic project build

The build command helps you with:

  • Compiling code

  • Running tests

  • Creating artifacts (executables)

The build system is based on Gradle and the XP Gradle plugin.

The "project build" command is an alias for the Gradle Wrapper, which must be located in your project through a file called .gradlew (linux/mac) or gradlew.bat (windows). The Gradle Wrapper is by default available with all Starter Kits on Enonic Market.

You may also use the Gradle Wrapper directly by running ./gradlew build (linux/mac) or gradlew build (windows) from your projects directory.

Clean

Alias for the gradlew clean command

$ enonic project clean

Deploy

As developers, we continuously need to deploy and test our code. Following command will build current project and deploy it to associated sandbox:

$ enonic project deploy [name]

Options:

Option Description

--dev

Run enonic XP distribution in development mode

name

sandbox name to deploy to (overrides associated sandbox)

If sandbox name is provided, it overrides the sandbox associated with the project for this time only.
Example deploying current project to 'otherSandbox' sandbox:
$ enonic project deploy otherSandbox

Gradle

In case you want to run arbitrary gradle task or group multiple ones in one command you can use following command:

$ enonic project gradle [tasks / flags ...]

The text after gradle is sent directly to gradlew, without modifications.

Options:

Option Description

tasks

a space delimited list of gradle tasks and flags to invoke

The difference between enonic project gradle clean build deploy and gradlew clean build deploy is that the former uses sandbox and enonic XP distribution configured for the project, while latter uses system wide settings.
Example running gradle clean build deploy:
$ enonic project gradle clean build deploy

Install

To install current project to running enonic instance

$ enonic project install
Enonic XP instance must be running when executing this command !

Install command does 2 things:

  • Builds the project

  • Installs built project to a running enonic XP instance using XP API

Options:

Option Description

-a, --auth

Authentication token for basic authentication in the following format <user:password>

if auth param is missing and there is no valid session CLI will look for ENONIC_CLI_REMOTE_USER and ENONIC_CLI_REMOTE_PASS environment variables. See configuration section.

Shell

This is an advanced command to export project JAVA_HOME and XP_HOME variables to a new shell. Following command starts a new shell bound to project sandbox and enonic XP distribution

$ enonic project shell
Run quit command to exit enonic shell. Parent shell environment is not modified.

Env

This command is currently not available on Windows.

If you are an expert user loving your shell you can export project JAVA_HOME and XP_HOME environment variables as strings to be used there

$ eval $(enonic project env)
Unlike enonic project shell command, this one will modify your current shell environment varialbes. Shell restart is needed to undo the changes.

Contents