Skip to content
Search

    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. All known root folders (app, db, and srv) or those configured in the build tasks are built.

    By default, cds build derives 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.

    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 used for Node.js production builds :

    {
      "build": {
        "target": "gen",
        "tasks": [
          { "for": "hana", "src": "db", "options": {"model": ["db","srv"] } },
          { "for": "nodejs", "src": "srv", "options": {"model": ["db","srv"] } }
        ]
      }
    }
    

    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 Deployment
      • mtx-extension: Creates a deployment layout (extension.tgz file) for an MTX extension project, which is required for extension activation using cds push. 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.
      All build tasks support the option model of type string or array of string. The given list of folders or individual .cds file names is resolved based on the given project folder which is the project’s root folder by default. cds build uses the compiled model for further model processing, for example, the java build task creates EDMX files describing the OData service APIs.

    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" }
    }
    

    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.

    Learn more about cds env get

    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 } }
        ]
      }
    }
    

    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.