Customizing cds build
Custom Build Configurations
cds build
executes build tasks on your project folders to prepare them for deployment. Build tasks compile source files (typically CDS sources) and create the required artifacts, for example, EDMX files, SAP HANA design-time artifacts, and so on. By default, cds build
dynamically determines the build tasks from the CDS configuration and from the project context. See build task properties for a concrete list of the different build task types.
All known root folders (app, db, and srv) or those configured in the build tasks are built. CDS model folders and files defined by the required services of your project will also be included by default. For more details regarding the calculation of the concrete list of CDS models see cds.resolve.
TIP
If custom build tasks have been configured, all configured properties have precedence, which prevents the calculation of default values. For example, you want to configure the src folder and add the default models. To achieve this, do not define the model options in your build task. That way, the model paths will still be dynamically determined, but the src folder is taken from the build task configuration. So you benefit from the automatic determination of models, for example, when adding a new external services, or when CAP is changing any built-in service configuration values.
To control which tasks cds build
executes, you can add them as part of your project configuration in package.json or .cdsrc.json.
The following build tasks represent the default configuration dynamically determined by cds build
for a minimal Node.js project when executing cds build --production
or cds build --profile production
:
{
"build": {
"target": "gen",
"tasks": [
{ "for": "hana", "src": "db", "options": {"model": ["db","srv"] } },
{ "for": "nodejs", "src": "srv", "options": {"model": ["db","srv"] } }
]
}
}
{
"build": {
"target": "gen",
"tasks": [
{ "for": "hana", "src": "db", "options": {"model": ["db","srv"] } },
{ "for": "nodejs", "src": "srv", "options": {"model": ["db","srv"] } }
]
}
}
TIP
The executed build tasks are logged to the command line. You can use them as a blue print – copy & paste them into your CDS configuration and adapt them to your needs. See also the command line help for further details using cds build --help
.
Build Task Properties
Build tasks can be customized using the following properties:
for
: Target technology for which the build is executed. Currently supported types are:hana
: Creates a deployment layout for the SAP HANA Development Infrastructure (HDI) if an SAP HANA database has been configured.nodejs
(deprecated:node-cf
): Creates a deployment layout using a self-contained folder ./gen for Node.js apps.java
(deprecated:java-cf
): Creates a deployment layout for Java apps.mtx
: Creates a deployment layout for Node.js applications using multitenancy, feature toggles, extensibility or a combination of these without sidecar architecture.
In this scenario the required services are implemented by the Node.js application itself which is the default for Node.js.mtx-sidecar
: Creates a deployment layout for Java or Node.js projects using multitenancy, feature toggles, extensibility or a combination of these with sidecar architecture.
Java projects have to use a sidecar architecture. For Node.js this is optional, but allows for better scalability in multitenant scenarios. Learn more about Multitenant Saas Application Deploymentmtx-extension
: Creates a deployment layout (extension.tgz file) for an MTX extension project, which is required for extension activation usingcds push
. Extension point restrictions defined by the SaaS app provider are validated by default. If any restriction is violated the build aborts and the errors are logged.
The build task is created by default for projects that have"cds": { "extends": "\<SaaS app name\>" }
configured in their package.json.
Learn more about Extending and Customizing SaaS Solutions
src
: Source folder of the module that is about to be build.dest
: Optional destination of the modules builds, relative to the enclosing project. The src folder is used by default.options
: Sets the options according to the target technology.model
: It has type string or array of string. The given list of folders or individual .cds file names is resolved based on the current working dir or the project folder passed to cds build. CDS built-in models (prefix @sap/cds*) are added by default to the user-defined list of models. Learn more about Core Data Services (CDS)
Note: Alternatively you can execute build tasks and pass the described arguments from command line. See also cds build --help
for further details.
Build Target Folder
If you want to change the default target folder, use the target
property in .cdsrc.json or package.json. It is resolved based on the root folder of your project.
{
"build": { "target" : "myfolder" }
}
{
"build": { "target" : "myfolder" }
}
Node.js
Node.js projects use the folder ./gen below the project root as build target folder by default.
Relevant source files from db or srv folders are copied into this folder, which makes it a self-contained folder that is ready for deployment. The default folder names can be changed with the folders.db, folders.srv, folders.app configuration. Or you can go for individual build task configuration for full flexibility.
Project files like .cdsrc.json or .npmrc located in the root folder or in the srv folder of your project are copied into the application's deployment folder (default gen/srv). Files located in the srv folder have precedence over the corresponding files located in the project root directory. As a consequence these files are used when deployed to production. Make sure that the folders do not contain one of these files by mistake. Consider using profiles development
or production
in order to distinguish environments. CDS configuration that should be kept locally can be defined in a file .cdsrc-private.json.
The contents of the node_modules folder is not copied into the deployment folder. For security reasons the files default-env.json and .env are also not copied into the deployment folder.
You can verify the CDS configuration settings that become effective in production
deployments. Executing cds env --profile production
in the deployment folder gen/srv will log the CDS configuration used in production environment.
Note:cds build
provides options you can use to switch on or off the copy behavior on build task level :
{
"build": {
"tasks": [
{ "for": "nodejs", "options": { "contentCdsrcJson": false, "contentNpmrc": false } },
{ "for": "hana", "options": { "contentNpmrc": false } }
]
}
}
{
"build": {
"tasks": [
{ "for": "nodejs", "options": { "contentCdsrcJson": false, "contentNpmrc": false } },
{ "for": "hana", "options": { "contentNpmrc": false } }
]
}
}
Java
Java projects use the project's root folder ./ as build target folder by default.
This causes cds build
to create the build output below the individual source folders. For example, db/src/gen contains the build output for the db/ folder. No source files are copied to db/src/gen because they're assumed to be deployed from their original location, the db/ folder itself.