Detailed insight in the standard XP build system
|We recommend using Enonic CLI to control your builds by default.|
By default, XP projects use Gradle as the main build tool. This is a highly flexible Java-based utility that builds on the popular Maven project tools and code repository structures. Enonic provides a Gradle plugin that greatly simplifies the build process. If you used the starter-vanilla project to initialize your project, you will have all the basic tools you need to get going.
build.gradle file located at your project root defines all the dependencies to other libraries.
There are three standard scopes (keywords) used in the dependency list
Compile (default gradle scope, compiles library and adds it to class path - standard for pure Java libraries)
Include (XP custom scope that merges the /src/main/resources folder in the library with your project - any code in your project overwrites the library files)
Webjar (Extracts the content of the specified Webjar - http://www.webjars.org/ - placing it into the assets folder, using the version number as root folder)
Enonic CLI automatically detects and uses project relative environment variables based on your XP distro and Sandbox.
If you plan to invoke Gradle directly, you will need to setup these variables manually
The following environment variables need to be defined:
Defines the location of the home folder (typically the home folder within your sandbox)
Defines the location of Java to support execution of Gradle (typically the
jdkfolder within your XP distro)
To set these variables use one of the following approaches:
Enonic CLI supports opening a new shell with environment variables automatically set:
enonic project shell
Use Enonic CLI to load environment variables into your current shell:
$(enonic project env)
Manually set environment variables for your project:
export XP_HOME=/path/to/sandbox/home export JAVA_HOME=/path/to/xp-distro/jdk
set XP_HOME=c:\path\to\sandbox\home set JAVA_HOME=c:\path\to\xp-distro\jdk
The Gradle Wrapper is a file located in your projects root:
gradlew for Linux/MacOS and
gradle.bat for Windows.
The wrapper will download all necessary files to run Gradle and execute project specific build commands.
| The gradle wrapper may also be invoked directly from Enonic CLI using
enonic project build command automatically wraps and invokes the Gradle Wrapper.
With environment variables set, you may use Gradle directly to get the job done:
From your project folder root execute the following command:
The build will place any output artifacts in the project’s build/libs/ folder.
enonic project deploy command builds and deploys an app to your sandbox.
You may do the same using Gradle directly:
The artifact is copied into the following location:
$XP_HOME/deploy, where XP will automatically pick it up.
|XP apps deployed via file (locally) are presented with a small blue icon in the Applications tool in XP Admin.|
You may activate dev mode when starting XP as follows:
- Enonic CLI
enonic sandbox start --dev
- Linux/MacOS directly
- Windows directly
Gradle also supports a continuous build mode. This will monitor your project assets for changes and run the specified task when something changes.
To use this with the
deploy task, simply run the following command:
./gradlew deploy --continuous
This will deploy and reload the application on the server when something changes in your project. The continuous deployment mode is most useful when coding Java, or other changes that require a full compile and re-deploy.