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 content of the library and its dependencies with your project - any code in your project overwrites the library files)
Webjar (Extracts the content of the specified Webjar - https://www.webjars.org/ - placing it into the assets folder, using the version number as root folder)
The XP Home folder contains directories specific to a single XP instance. The home folder can be copied to multiple locations for developers working on multiple isolated projects. Enonic XP uses, by default, the
home folder within your distribution as XP Home.
Enonic XP uses, by default, the JDK/JRE within your distribution or the location of your Java installation is used as Java Home. Gradel uses, by default, the location of your Java installation is used as Java Home
If you wish to change this behaviour, the following environment variables can be defined:
Defines the location of the home folder
Defines the location of Java
To set these variables use one of the following approaches:
export XP_HOME=/path/to/home export JAVA_HOME=/path/to/xp-distro/jdk
set XP_HOME=c:\path\to\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.
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:
- Enonic CLI
enonic project build
The build will place any output artifacts in the project’s build/libs/ folder.
To builds and deploy an app to your XP Home, make sure XP_HOME is defined and execute the following command
- Enonic CLI
enonic project deploy
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.|
As the name implies, development mode is intended only for development use and should not be used in production. Doing so would cause both security and performance issues.
Because of the way XP reads source files directly in development mode, it has a few limitations:
If development mode does not work for you, try using continuous build mode instead.
Development mode also disables some of XP’s caching mechanisms. To make the development workflow as smooth as possible, XP tries to invalidate caches for your static assets. This is to prevent you from getting stale resources so that what you see in the browser is always as up to date as possible.
To activate development mode, use one of the following commands to start your sandbox:
- Enonic CLI
enonic sandbox start --dev
Gradle also supports a continuous build mode. In continuous build mode, Gradle will monitor your project assets for changes and run a task you specify when something changes.
Continuous builds come in handy when the changes you’re working on require a full compile and redeploy, such as when you’re working with Java or need to build/compile client-side assets with an external build tool (such as webpack).
If you don’t need a full compile or don’t need to run external build tools, you may be better served by using XP’s development mode.
To use continuous Gradle tasks, specify your task and pass the
--continuous option. The following examples use the
deploy task, but you can also use any other defined Gradle tasks:
- Enonic CLI
enonic project gradle deploy --continuous
./gradlew deploy --continuous
gradlew.bat deploy --continuous