ohpm supports distinguishing between project-level and module-level oh-package.json5 files since 5.0.0. The following is a breakdown of each:
You can package each module in a standard DevEco Studio project into a HAR and publish it to the central repository of OpenHarmony third-party libraries. All packages published to the repository must include a module-level oh-package.json5 file to describe the basic information of the current package.
Configuration Item | Name | Description | Requirement | Type | Default Value | Remarks |
|---|---|---|---|---|---|---|
Development-specific version | modelVersion | Development-specific version number. | Mandatory | String | None | Set the development-specific version number. The default value is the model version matching DevEco Studio. For example, modelVersion matching DevEco Studio 6.1.1 Release is 6.1.1. To modify modelVersion, ensure that the new value is not earlier than 5.0.0 and not later than the model version matching DevEco Studio. |
Description settings | description | Description of the third-party library. | Optional | String | None | Project information. |
Dependency settings | dependencies | Production dependencies. | Optional | Object | {} | Dependencies that participate in the compilation and runtime phases. This involves declaring third-party libraries that need to be imported in the code. (Avoid configuring production dependencies in the project-level oh-package.json5 file.) |
devDependencies | Development dependencies. | Optional | Object | {} | Development dependencies that are only needed during the development or testing phases of the project. Do not include in this field any dependencies that may be published with components that depend on them to a target device (such as a phone). | |
dynamicDependencies | Dynamic dependencies. | Optional | Object | {} | HSP modules on which the project dynamically depends. Avoid configuring dynamic dependencies in the project-level oh-package.json5 file. | |
overrides | Dependency overrides. | Optional | Object | {} | Version used to replace a package in the dependency tree. For details, see overrides. | |
overrideDependencyMap | Dependency overrides. | Optional | Object | {} | Dependencies used to replace sub-dependencies of packages in the dependency tree. For details, see overrideDependencyMap. | |
exclusions | Sub-dependencies exclusion for third-party dependencies. | Optional | Object | {} | Sub-dependencies to exclude. One or more sub-dependencies of third-party dependencies (remote dependencies and local file dependencies) can be removed. For details, see exclusions. | |
Others | scripts | Custom script | Optional | Object | {} | This field maintains a mapping between script aliases and script content. You can run the ohpm run <script alias > command to execute the corresponding script. |
hooks | Hook | Optional | Object | {} | Hook setting for installation or uninstallation, including fields preInstall, postInstall, preUninstall, postUninstall, preVersion, postVersion, prePublish, postPublish. Only hooks in the current project can be executed. Hooks in dependencies cannot be executed. | |
parameterFile | Path of the parameterization configuration file | Optional | String | None | Whether to enable parameterization. Parameterization is enabled if this field is configured and is disabled otherwise. You must also specify the path to the parameterization configuration file. For details, see parameterFile. | |
properties | Parameter for multi-environment dependency management | Optional | Object | {} | Properties for managing dependencies across multiple environments. After configuring dependencies using the parameterFile field, you can use this parameter within the parameterFile field. For details, see properties. NOTE: Scenarios such as configuring different parameterFile files for the debug and beta environments to implement different package dependency management are referred to as multi-environment scenarios. |
Avoid configuring non-development dependencies in the project-level configuration file. In other words, module-specific dependencies and dynamic dependencies should be declared in the respective HSP or HAR modules.
The module-level oh-package.json5 file is located in the root directory of each module in the project. It describes information related to the current module when it is depended on by other modules, including: name, version number, entry files, and sub-dependencies.
Configuration Item | Name | Description | Mandatory/Optional | Value Type | Default Value | Remarks |
|---|---|---|---|---|---|---|
Description settings | name | Name of the third-party library. | Mandatory | String | None | Unique identifier for the module when it is installed as a dependency. Name in the format of @group/package name or package name, with a length of [1, 128]. The name must be globally unique in the app. It is recommended that the name contain the organization name (specified with group) to facilitate management and identification. The name can contain exactly one at sign (@) and one path separator (/) only when there is an organization name (group). Organization name (group) format: 1. The value must start with a lowercase letter and can contain lowercase letters, digits, hyphens (-), and underscores (_). 2. The value cannot end with a hyphen (-) or underscore (_). 3. The value cannot contain keywords reserved for ArkTS. Package name format: 1. The value must start with a lowercase letter and can contain lowercase letters, digits, periods (.), hyphens (-), and underscores (_). 2. The value cannot end with a period (.), hyphen (-), or underscore (_). 3. The value cannot contain keywords reserved for ArkTS. |
version | Version number of the third-party library. | Mandatory | String | 1.0.0 | Version number of the module's build product (HAR/HSP). The value must follow the SemVer specification using the X.Y.Z (major.minor.patch) format, starting from 1.0.0. | |
description | Description of the third-party library. | Optional | String | None | Description of the built product (HAR/HSP), which helps make the module discoverable in searches. The value contains 0 to 512 characters. | |
keywords | Keywords. | Optional | Array | [] | A keyword array used for easy search, for example, ["tools", "project"]. | |
author | Author of the third-party library. | Mandatory/Optional | Object or string | None | An object or a string containing the name (mandatory), email (optional), and url (optional) fields. The name value can contain 1 to 128 characters, including letters, digits, periods (.), hyphens (-), underscores (_), spaces, and Chinese characters, email can contain 1 to 64 characters, and url can contain 1 to 256 characters.
This parameter is mandatory only when the library is published to the OpenHarmony third-party library repository. | |
homepage | Homepage link. | Optional | String | "" | The value usually is a link to a Gitee project. | |
repository | Repository address of the third-party library. | Optional | String | "" | Address of an open-source code repository. You can define whether the parameter is mandatory in the system settings on the private repository management page. | |
license | Open-source license used by the third-party library. | Mandatory/Optional | String | "ISC" | Open-source license of a project in compliance with specifications in spdx license. If the license is GPL, it is recommended that repository be specified. This parameter is mandatory only when an open-source third-party library is published to the OpenHarmony third-party library repository. | |
Dependency settings | dependencies | Production dependencies. | Optional | Object | {} | Configure dependencies involved in the compilation and runtime phases. You can declare third-party libraries that need to be imported in the code. |
devDependencies | Development dependencies. | Optional | Object | {} | Configure development dependencies that are only needed during the development or testing phases of the project. Do not include in this field any dependencies that may be published with components that depend on them to a target device (such as a phone). Dependencies introduced via devDependencies are not checked for circular dependencies. | |
dynamicDependencies | Dynamic dependencies. | Optional | Object | {} | Configure dynamic dependencies for HSP modules. This field is used when the HSP module needs to be dynamically loaded. | |
File settings | main | Main file | Mandatory | String | None | Main file to be loaded. |
types | Type | Optional | String | "" | Name of the type declaration file. If a new type is defined using TypeScript for other developers to use, you must specify the corresponding declaration file (typically a .d.ts or .d.ets file). | |
oh-exports | Files to export | Optional | Object | {} | This field controls which files in the module are exported, thereby managing the package visibility. Entire directories can be exported without file verification. Files with specific suffixes (such as .ets, .ts, and .js) can also be exported. For details, see the configuration example in oh-exports. | |
Compatibility check configuration | compatibleSdkVersion | SDK version. | Optional | String | None | This field sets the SDK version used by third-party library developers. It is automatically filled in by Hvigor during the build and used in SDK compatibility testing. During execution of prepublish and publish, ohpm checks this field (for non-null and length validation) and, if any error is detected, displays a message at the log level specified through compability_log_level in the .ohpmrc file. For details, see Compatibility Field Configuration Example. |
compatibleSdkType | SDK type. | Optional | String | None | This field sets the SDK type used by third-party library developers. It is automatically filled in by Hvigor during the build and used in SDK compatibility testing. Example values are OpenHarmony and HarmonyOS. During execution of prepublish and publish, ohpm checks this field (for non-null and length validation) and, if any error is detected, displays a message at the log level specified through compability_log_level in the .ohpmrc file. For details, see Compatibility Field Configuration Example. | |
obfuscated | Whether to enable obfuscation. | Optional | Boolean | None | This field sets whether to enable obfuscation for third-party libraries. It is automatically filled in by Hvigor during the build and used in SDK compatibility testing. During execution of prepublish and publish, ohpm checks this field (for non-null validation) and, if any error is detected, displays a message at the log level specified through compability_log_level in the .ohpmrc file. For details, see Compatibility Field Configuration Example. | |
nativeComponents | Native .so dependencies. | Optional | Array | None | This field sets the .so dependencies used by third-party library developers. It is automatically filled in by Hvigor during the build and used in SDK compatibility testing. For self-introduced .so dependencies stored under the libs directory, you must manually maintain this array. Each array element is an object configurable with the following fields: name, compatibleSdkVersion, and compatibleSdkType. During execution of prepublish and publish, if the package contains .so files, ohpm checks this field and, if any error is detected, displays a message at the log level specified through compability_log_level in the .ohpmrc file. If there are no .so files in the package, this field will not be checked. For details, see Compatibility Field Configuration Example. | |
Others | artifactType | Type | Optional | String | "original" | The value is either original or obfuscation. original indicates that the source code is released (.ts/.ets). obfuscation indicates that the source code is obfuscated before being released. |
scripts | Custom script | Optional | Object | {} | This field maintains a mapping between script aliases and script content. You can run the ohpm run <script alias > command to execute the corresponding script. | |
hooks | Hook | Optional | Object | {} | This field configures hook settings for installation or uninstall, including fields preInstall, postInstall, preUninstall, postUninstall, preVersion, postVersion, prePublish, and postPublish. Only hooks in the current project can be executed. Hooks in dependencies cannot be executed. | |
category | Trustlist for rule check | Optional | String | {} | The trustlist is automatically generated after being configured on the private repository management page. Each item in the trustlist must be a character string consisting of uppercase letters, lowercase letters, or underscores (_), and multiple lists are separated by semicolons (;). Rule check is not performed for the items in the trustlist. | |
packageType | Package type | Optional | String | InterfaceHar | This field indicates whether a module is an HSP. It is automatically generated when a shared library is created and is set to InterfaceHar by default. If a static library does not contain this field, the module is identified as a HAR package. | |
dependencyMode | BundledHar type | Optional | String | loose | This field is automatically generated during build. Manual configuration is not recommended. This field indicates whether bundledAllDependencies is enabled for the current HAR compilation. The value is set to bundled when enabled, or loose (or omitted) when not enabled. The third-party central repository supports only the values bundled and loose. Other values will cause verification failures. |
Requirements for dependency naming:
1. In the oh-package.json5 file, when local dependencies are declared under dependencies, devDependencies, or dynamicDependencies, the names of the dependencies configured can be inconsistent with the names of the dependent packages (that is, the names configured in the oh-package.json5 files within the packages). However, this practice is discouraged. By default, ohpm will report warnings for such discrepancies.
To treat these warnings as errors and halt command execution, set enforce_dependency_key to true in the .ohpmrc file or useNormalizedOHMUrl to true under the strictMode field in the project-level build-profile.json5 file.
2. When you use parameterized configurations, the dependency name must match the dependency package name (as configured in oh-package.json5). Any inconsistency will result in an error, causing the command execution to be interrupted.
3. Avoid using invalid escape characters (such as \a, \e, and \o) or Unicode codes (such as \uxxxx) in the oh-package.json5, overrideDependencyMap, and parameterFile files.
Third-party library developers may use a different version of the SDK from the one used for compiling the project that integrates the third-party library. To address this potential inconsistency, ohpm adds compatibility field testing configurations. Here is an example of the configurations:
{
"name": "library",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"license": "Apache-2.0",
"dependencies": {
"liblibrary.so": "file:./src/main/cpp/types/liblibrary"
},
"compatibleSdkVersion": "12",
"compatibleSdkType": "HarmonyOS",
"obfuscated": false,
"nativeComponents": [
{
"name": "liblibrary.so",
"compatibleSdkVersion": "12",
"compatibleSdkType": "HarmonyOS"
}
]
} Perform the following operations to create an oh-package.json5 file:
Navigate to the directory of the package:
cd /path/to/package
Run the initialization command and set related parameters according to the questionnaire.
For a module without namespaces, run the following command:
ohpm init
For a module with namespaces, run the following command:
ohpm init --group group_name
If you skip filling in the questionnaire and create a default file, add the --yes parameter to the initialization command line.
ohpm init --yes
The following is an example of the default oh-package.json5 file:
{
"name": "package_name",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"author": "",
"license": "ISC",
"dependencies": {}
} ohpm supports three types of dependencies: dependencies, devDependencies, and dynamicDependencies. Dependencies can be imported by specifying the version number, version range, tag, local .har/.tgz file path, or local source code directory, or using @module with the module name (example: "module_key": "@module:module_name"). If the version number of a dependent third-party library is set to *, the dependent package will use the latest version of that third-party library.
1. Since DevEco Studio 6.0.0 Beta1, the @module configuration mode is supported. Since DevEco Studio 6.0.2 Beta1, dependencies introduced via devDependencies are not checked for circular dependencies.
2. module_name in the @module configuration must exist in the modules node of the project/build-profile.json5 file or project/.hvigor/dependencyMap/dependencyMap.json5 (generated by Hvigor) file.
3. module_key in the @module configuration must be the same as the name configured in the oh-package.json5 file in the module directory specified by @module:module_name.
{
"dependencies": {
// Import dependencies by specific version number, which adheres to the semver standard.
"specific_version": "1.0.0",
// Import dependencies by version number range. ^ means to import the latest version within the major version (for example, 1.x.x). ~ means to import the latest version within the minor version (for example, 1.0.x). Priority is given to the latest stable version that fits within the range.
"scope_version": "^1.0.1",
// Import dependencies by tag. This example imports dependencies whose version tag is beta.
"tag_version": "tag:beta",
// Import a local .har or .tgz file.
"local_file": "file:./xx.har",
// Import the local source code, which can be source code from other local modules. In this example, the local module1 module is imported.
"local_source_code": "file:../module1"
// If the Foo module exists in the project, the modules node in the build-profile.json5 or dependencyMap.json5 file contains the Foo module, whose name in the oh-package.json5 file is foo_test.
"foo_test": "@module:Foo"
},
"devDependencies": {
// The dependency import type is the same as that of dependencies.
},
"dynamicDependencies": {
// The dependency import type is the same as that of dependencies.
}
} As shown in the following oh-package.json5 configuration, module ma depends on module mb via dependencies, while module mb in turn depends on module ma via devDependencies, thereby creating a circular dependency.
// oh-package.json5 of module ma
{
"name": "ma",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"mb": "../mb"
}
}
// oh-package.json5 of module mb
{
"name": "mb",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"ma": "../ma"
}
} The ohpm client supports the override mechanism since version 1.4.0. You can add the overrides configurations to the oh-package.json5 file at the project level (that is, oh-package.json5 in the root directory of the project) to replace the dependency in the dependency tree with another version. The replacement version can be specified by a version number, a version range, an existing local HAR package or source code directory, the parameterFile configuration (for example, "foo": "@param:dependencies.foo"), or the @module with the module name to point to the module directory (for example, "module_key": "@module:module_name").
For example, to ensure that foo 1.0.0 is always installed, add the following configuration to the project-level oh-package.json5 file:
{
"overrides": {
"foo": "1.0.0"
}
} If the foo source code, HAR package, or @module configuration exists on the local host, you can configure the following information in the project-level oh-package.json5 file to ensure that the foo always uses your local version:
{
"overrides": {
// If the Foo module exists in the project, the modules node in the build-profile.json5 or dependencyMap.json5 file contains the Foo module, whose name in the oh-package.json5 file is foo_test.
// "foo_test": "@module:Foo"
// The foo source code directory exists on the local host, for example, the foo directory in the root directory of the project.
// "foo": "file:./foo"
// The HAR file of foo exists on the local host, for example, foo.har in the libs directory in the root directory of the project.
"foo": "file:./libs/foo.har"
}
} exclusions is supported since ohpm 5.3.0. You can add exclusions configurations to the project-level oh-package.json5 file (that is, the oh-package.json5 file in the project root directory) to remove one or more sub-dependencies from a third-party dependency (remote dependency or local file dependency).
// key:value format "[@group/]libname[@spec]" : ['exclude_sub_libname']
{
"exclusions": {
"@ohos/lib1@1.0.0": ['@ohos/sub_lib1'] // Exclude the sub-dependency @ohos/sub_lib1 of the remote dependency @ohos/lib1.
"@ohos/lib2@./lib2.har": ['@ohos/sub_lib2'] // Exclude the sub-dependency @ohos/sub_lib2 of the local file dependency @ohos/lib2.
}
} The following shows how to remove dependencies configured in dependencies and dynamicDependencies in oh-package.json5 of a remote dependency or local file dependency. In this example, <project> indicates the root directory of the project.
1. The module-level oh-package.json5 file declares the dependencies to be installed: @ohos/lib1 and @ohos/lib2.
{
"name": "entry",
"version": "1.0.0",
"description": "Please describe the basic information.",
"dependencies": {
"@ohos/lib1": "1.0.0" // Remote dependency
"@ohos/lib2": "file:../lib2.har" // Local file dependency
}
}
// oh-package.json5 configuration of @ohos/lib1
{
"name": "@ohos/lib1",
"version": "1.0.0",
"description": "Please describe the basic information.",
"dependencies": {
"@ohos/lib1_sub1": "1.0.0" // Sub-dependency 1
"@ohos/lib1_sub2": "2.0.0" // Sub-dependency 2
}
}
// oh-package.json5 configuration of @ohos/lib2
{
"name": "@ohos/lib2",
"version": "1.0.0",
"description": "Please describe the basic information.",
"dependencies": {
"@ohos/lib2_sub1": "1.0.0" // Sub-dependency 1
"@ohos/lib2_sub2": "2.0.0" // Sub-dependency 2
}
} 2. Configure exclusions in the project-level oh-package.json5 file as follows, where lib2.har is placed in the root directory of the project.
{
"modelVersion": "6.1.1",
"description": "Please describe the basic information.",
"exclusions": {
"@ohos/lib1@1.0.0": ['@ohos/lib1_sub1'], // Exclude the sub-dependency @ohos/lib1_sub1 of the remote dependency @ohos/lib1.
"@ohos/lib2@./lib2.har": ['@ohos/lib2_sub2'] // Exclude the sub-dependency @ohos/lib2_sub2 of the local file dependency @ohos/lib2.
}
} 3. Run the ohpm install command.
ohpm install --all
4. After ohpm is installed, run the ohpm list -d 10 command in the entry directory. The dependency structure is as follows:
entry 1.0.0 <project>\entry ├─┬ @ohos/lib1 1.0.0 │ └── @ohos/lib1_sub2 1.0.0 // @ohos/lib1_sub2 is installed and @ohos/lib1_sub1 is excluded. ├─┬ @ohos/lib2 <project>\lib2.har └── @ohos/lib2_sub1 1.0.0 // @ohos/lib2_sub1 is installed and @ohos/lib2_sub2 is excluded.
ohpm supports parameterization configuration. You can configure a parameterization file (in JSON5 format) in the root directory of the project for maintaining module or dependency version information. Modules are configured based on the versions in the file, allowing you to quickly switch dependency versions in different build scenarios. In addition, you can specify a parameterization file using commands to reduce the difficulty in changing module and dependency versions in pipeline scenarios.
ohpm supports parameterization configuration since version 1.6.0. You can add the parameterFile configuration to the project-level oh-package.json5 file and specify the parameterization file path following the configuration rules below:
Example of a project-level oh-package.json5 file:
{
"modelVersion": "6.1.1",
"description": "Please describe the project information.",
"parameterFile": './parameterFile/parameterFile.json5', // Enable parameterization and specify the path of the parameterization configuration file.
"overrides": {
"libtest1": "@param:dependencies.libtest1", // All versions of dependencies named libtest1 are replaced with 1.0.1.
"libnative": "@param:dependencies.libnative" // All versions of dependencies named libnative are replaced with the libnative source code dependency path.
}
} Example of a module-level oh-package.json5 file:
{
"name": "parameter-test",
"version": "@param:version", // Must start with @param:.
"description": "test desc.",
"main": "index.ets",
"author": "test author",
"license": "ISC",
"dependencies": {
"libtest1": "@param:dependencies.libtest1"
},
"devDependencies": {
"libtest2": "@param:devDependencies.libtest2"
},
"dynamicDependencies": {
"libtest3": "@param:dynamicDependencies.libtest3"
}
} Configuration Example of the File Specified by parameterFile
{
"version": "1.0.0",
"dependencies": {
"libtest1": "1.0.1",
"libnative": "../libnative" // Relative to the directory where the parameterFile configuration file is located.
},
"devDependencies": {
"libtest2": "*"
},
"dynamicDependencies": {
"libtest3": "latest"
}
} A code repository has multiple HAR/HSP modules. When publishing a package, you typically need to manually modify the version numbers of all modules before packaging and releasing. If there are many modules, this can be cumbersome and inefficient. You are advised to use parameterization configuration to address this issue.
If the versions of all modules are different:
As shown in the following project structure, the version fields in the oh-package.json5 files of all modules are configured with parameterized versions (starting with '@param:'), and the versions of different modules are all different but are globally managed by the parametrization configuration file parameter.json. Before packaging, you only need to modify the version of the relevant module in the parameter.json file and then build all modules. During the packaging and building process, all parameterized versions of the modules will be replaced with the specific versions configured in parameter.json (for example, @param:har1 will be replaced with 1.0.0).
AppTest
└── har1 (module)
└── oh-package.json5
└── "version": "@param:har1"
└── har2 (module)
└── oh-package.json5
└── "version": "@param:har2"
... harn (module)
└── oh-package.json5
└── "version": "@param:harn"
└── oh-package.json5
└── "parameterFile": "./parameter.json"
└── parameter.json (parametrization configuration file)
└── "har1": "1.0.0"
└── "har2": "2.0.0"
...
└── "harn": "n.0.0" If the versions of all modules are the same:
As shown in the following project structure, all modules use the same parameterized version (@param:module_version). Before packing, you only need to modify the value of module_version in parameter.json and then build all modules. During the packing and building process, all parameterized versions of the modules will be replaced with the version corresponding to module_version in parameter.json (for example, @param:module_version will be replaced with 1.0.0).
AppTest
└── har1 (module)
└── oh-package.json5
└── "version": "@param:module_version"
└── har2 (module)
└── oh-package.json5
└── "version": "@param:module_version"
... harn (module)
└── oh-package.json5
└── "version": "@param:module_version"
└── oh-package.json5
└── "parameterFile": "./parameter.json"
└── parameter.json (parametrization configuration file)
└── "module_version": "1.0.0" The properties parameter has been added in the project-level oh-package.json5 file since ohpm 6.1.2.268, and this configuration item is designed for multi-environment dependency management.
After configuring dependencies using parameterFile, you can use the properties parameter in the parameterFile field to manage dependencies across multiple environments of the project.
Parameter reference methods
The following three parameter reference methods are supported:
// Obtain parameter values using the ${key} syntax.
{
"modelVersion": "6.1.1",
"description": "Please describe the project information.",
"parameterFile": '${ohpm_environment}',
"properties": {
"ohpm_environment":"./parameterFile/debug.json5",
}
}
// Obtain parameter values using the JSON property access syntax.
{
"modelVersion": "6.1.1",
"description": "Please describe the project information.",
"parameterFile": '${versions.release}',
"properties": {
"ohpm_environment":"./parameterFile/debug.json5",
"versions": {
"release": "./parameterFile/release.json5",
}
}
}
// Obtain parameter values through string concatenation.
{
"modelVersion": "6.1.1",
"description": "Please describe the project information.",
"parameterFile": './parameterFile/${versions.debug}.json5',
"properties": {
"ohpm_environment":"",
"versions": {
"debug": "debug-1.0.0",
}
}
} overrideDependencyMap, used to override the dependency relationships of source modules or third-party libraries, is supported in since ohpm 1.7.0. You can add an overrideDependencyMap configuration in the project-level oh-package.json5 file and set it to key-value pairs, where the key indicates the dependency identifier, and the value indicates the path to the dependency relationship override file. During dependency installation, ohpm will replace all the direct child dependencies of a certain node in the dependency tree with the dependencies configured in the corresponding dependency relationship override file. The dependency types supported in the dependency relationship override file include dependencies, devDependencies, and dynamicDependencies. By using the overrideDependencyMap mechanism, you can dynamically change dependencies in different scenarios.
Additionally, you can use the projectPackageJson configuration item in the .ohpmrc file to override the configurations in the oh-package.json5 file in the project's root directory. For details, see related descriptions in ohpmrc.
Description
"[@group/]libname[@version]" : "config_path", where [@group/]libname[@version] is the dependency identifier (key), and config_path is the path to the dependency relationship override file (value).
{
"overrideDependencyMap": {
"@group/libname": "dep-test.json5"
}
} Scenario Example for overrideDependency
{
"name": "entry",
"version": "1.0.0",
"main": "Index.ets",
"license": "Apache-2.0",
"dependencies": {
"libbase": "1.0.0"
}
} {
"name": "libbase",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"lib1": "1.0.0" // Sub-dependency
}
} {
"name": "overridedependencymaptest",
"version": "1.0.0",
"description": "Please describe the basic information.",
"overrideDependencyMap": {
"libbase": "D:\\overrideDependencyMapTest\\dep-debug.json5" // overrideDependencyMap configuration. Multiple entries are allowed.
}
} {
"dependencies": { // Dependency configuration
"lib1": "2.0.0",
"log4js": "2.0.0"
},
"devDependencies": {
},
"dynamicDependencies": {
}
} entry 1.0.0 D:\overrideDependencyMapTest\entry
└── libbase 1.0.0
└── lib1 2.0.0
└── log4js 2.0.0 Since ohpm 6.1.1.816, the oh-exports field can be used to control files exported from modules to manage package visibility.
{
"oh-exports": [
'src',
'./src',
'src/main',
'src/main/ets/components/MainPage1.ets',
'src/main/ets/components/MainPage2.ts'
'src/main/ets/components/MainPage2.js'
]
} Using the projectPackageJson configuration in the .ohpmrc file provides a way to override the project-level oh-package.json5 configurations, including the overrides and overrideDependencyMap fields. The following are the details on how to use this configuration and its constraints:
projectPackageJson:<project_root>=<config_path>, where projectPackageJson:<project_root> is the key, and config_path is the value. Set the key to the absolute path to the project's root directory, and set the value to the path to the JSON5 file that will override the configurations in the project-level oh-package.json5 file.
projectPackageJson:D:\test\TestProject=projectPackageJson.json5
Example
This example demonstrates how to configure different environment settings for the same project using projectPackageJson in the .ohpmrc file. When these configurations take effect, they directly override the corresponding configurations in the project-level oh-package.json5 file.
registry=http://localhost:8088/repos/ohpm log_level=debug strict_ssl=false projectPackageJson:D:\overrideDependencyMapTest=oh-pkg-debug.json5 // Debug environment configuration projectPackageJson:D:\overrideDependencyMapTest=oh-pkg-release.json5 // Release environment configuration; if multiple configurations exist for the same project, the last one will take effect by default.
{
"overrideDependencyMap": {
"libbase": "D:\\overrideDependencyMapTest\\dep-release.json5"
}
} {
"dependencies": {
"lib1": "1.0.0",
"lib2": "2.0.0",
"lib3": "3.0.0"
}
} {
"name": "overridedependencymaptest",
"version": "1.0.0",
"description": "Please describe the basic information.",
"overrideDependencyMap": {
"libbase": "D:\\overrideDependencyMapTest\\dep-release.json5"
}
} entry 1.0.0 D:\overrideDependencyMapTest\entry
└── libbase 1.0.0
└── lib1 1.0.0
└── lib2 2.0.0
└── lib3 3.0.0 The oh-package-lock.json5 file is used to lock all dependent versions and cache metadata of the dependencies. You are not advised to manually modify the file content or use other analysis tools to directly read the file content.
Instead, commit the oh-package-lock.json5 file to the code repository for version management. The benefits are as follows: