Publishing a Maven Artifact to Self-Hosted Repos via a Build Task
During software development, teams often rely on private packages to protect intellectual property and promote code reuse. However, fetching dependencies from Maven repositories can introduce permission issues or network latency, leading to build failures. Secure publishing and efficient retrieval of private packages remain critical challenges. This practice describes how to publish a private package to a Maven repository via a build task and fetch its dependencies from the repository to complete the build task, resolving the challenges mentioned earlier.
Billing
This function requires CodeArts Repo and CodeArts Build. You need to purchase a CodeArts package.
Prerequisites
- You already have a project. If no project is available, create one. For example, create a project named project_maven.
- You have been granted permissions to upload, download, and view packages in the current repository. For details, see Configuring Repository Permissions.
Creating a Maven Repository
- Use your Huawei Cloud account to access self-hosted repos.
- On the Self-hosted Repos page, click Create Repository in the upper-right corner.
- Select Local Repository as the repository type, enter the repository name maven_local, and select Maven as the package type. Select project_maven created in Prerequisites from the Project drop-down list.
- Click OK. The created Maven repository is displayed in the Repo View.
Configuring Package Versions in CodeArts Repo
- Log in to the Huawei Cloud console with your Huawei Cloud account.
- Click
in the upper-left corner and choose Developer Services > CodeArts from the service list. - Click Access Service. The homepage of CodeArts is displayed.
- Choose from the top menu bar.
- In the displayed dialog box, select Merge Requests, and click the confirm button.
- On the Repo homepage, click Create Repository.
- Select project_maven from the Project drop-down list, select Template, and click Next.
- Search for the Java Maven Demo template, and click Next.
- Enter the repository name repo01 and click OK.
- Go back to Repo and click pom.xml to view the package configuration.

- On the package configuration page, the <version> field displays the version number of the current package. The default version number is 1.0.
Click
in the upper-right corner of the page to change the version number. Then, click OK to save the changes.
Publishing a Maven Artifact to Self-Hosted Repos via CodeArts Build
- After configuring the package version in Repo by referring to Configuring Package Versions in CodeArts Repo, click Create Build Task in the upper-right corner of the page.
- Select Template and click OK.
- Edit the Build with Maven action.
- Select the desired tool version. In this example, maven3.5.3-jdk8-open is used.
- Find the following command and delete # in front of this command-line.
#mvn deploy -Dmaven.test.skip=true -U -e -X -B
Find the following command and add # in front of this command.mvn package -Dmaven.test.skip=true -U -e -X -B
- Select Configure all POMs under Release to Self-hosted Repos, and select the Maven repository maven01 associated with the project.

- Click Save and Execute in the upper-right corner of the page to execute build task.
Viewing Packages in the Version View of a Maven Repository
- Use your Huawei Cloud account to access self-hosted repos.
- Select the self-hosted repo, locate the target maven repository, and find the Maven artifact uploaded by build task.
Set the package version in Repo by referring to Configuring Package Versions in CodeArts Repo and archive packages of multiple versions to self-hosted repos.
- Click the Version View tab.
In the package list, view the number of versions and the latest version of the package obtained from the build task.
- Click a name in the Package Name column. The Overview page for the latest version of the package is displayed.
- Click the Files tab, click
in the Operation column of the target package to download it to the localhost. - After modifying a package and setting a new version number, click Upload in the right of the target self-hosted repo to upload the latest version of the package.
The package list in the Version View displays the latest uploaded version of each package and the number of archived versions.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot