Updated on 2023-11-28 GMT+08:00

Q&A

What Is Cache? How Do I Clear Abnormal Cache?

CodeArts Build allows you to cache the dependencies in your private storage space. Once cached, the dependencies will not have to be pulled for future builds. This greatly accelerates builds.

  • Configuring cache setting

    Cache is enabled by default when a build task is created. You can change this setting in Build with Maven > Cache.

  • Clearing the cache

    Network jitter, concurrent builds, or other extreme conditions may result in abnormal cache. Consequently, build errors may occur. The following describes how to clear the abnormal cache.

    Before clearing cache, make sure you are well aware of the following precautions:

    • The cache directory is shared by multiple users of the same tenant. Frequent cache clearing may cause exceptions (file loss, often the case) in other users' builds. Therefore, clear cache only when the cache is abnormal. After the cache returns to normal, edit the task to delete the clearing command.
    • Use a detailed file path when clearing the cache. For example, to clear demo 1.0.0, run rm -rf /path/com/xx/demo/1.0.0. If an upper-level directory is entered in the cache clearing command, the next build will be slow or the dependency will be abnormal due to network problems.
    • For security purposes, the cache clearing command can be executed only in the Build with Maven action. If this command is executed in other actions, the clearing operation may not succeed or an error will be displayed indicating that the directory does not exist.
    If you have read the risk description carefully and understand and accept the risks, perform the following steps to clear the cache:
    1. Prepare the clearing command.
      • The format of the cache clearing command is rm -rf /repository/local/maven/{group_ID}/{artifact_ID}/{version}.
      • {Group_ID}, {Artifact_ID}, and {Version} are the groupId, artifactId, and version of the dependency.
        For example, if the dependency is as follows:
        <dependency>
        	<groupId>com.xx.devcloud</groupId>
        	<artifactId>demo</artifactId>
        	<version>1.0.9-SNAPSHOT</version>
        </dependency>

        The command for clearing the dependency is rm -rf /repository/local/maven/com/xx/devcloud/demo/1.0.9-SNAPSHOT.

    2. Edit the build task and configure the action Build with Maven.
    3. Find the mvn xxxx command, add a line before the command, enter the prepared clearing command, and save the task.
    4. Run the build task again.
    5. Edit the task again and remove the cache clearing command.

What Do Default Commands in Build with Maven Indicate?

The built-in default build commands of the build service are as follows:
# Function: packaging
Parameter description:
#              -Dmaven.test.skip=true: Skip unit test.
#              -U: Check for dependency update for each build so that the snapshot version dependency in the cache is always updated. However, this will lower performance.
#              -e -X: Print the debugging information. Use this parameter to locate difficult build problems.
#              -B: Run in batch mode to avoid the ArrayIndexOutOfBoundsException exception during log printing.
# Scenario: Used for packaging projects when unit tests are not required.
mvn package -Dmaven.test.skip=true -U -e -X -B

The meaning of each command/parameter is as follows:

  • mvn package: Use Maven to perform packaging. After this command is executed, a software package is generated in the target directory of the project. You can change the directory as required.
  • -Dmaven.test.skip=true: Skip the unit test. You are advised to retain this parameter.
  • -U: Check for dependency update for each build so that the snapshot version dependency in the cache is always updated. However, this will lower performance. You are advised to retain this parameter.
  • -e -X: Print the debugging information. Use this parameter to locate difficult build problems.
  • -B: Run in batch mode to avoid the ArrayIndexOutOfBoundsException exception during log printing.