How Maven publishes local projects to archiva

Time:2020-6-29

Many times, we may not want to publish our build code to a public Maven repository.

How to use Maven to publish some private projects to archiva.


This is actually quite simple.

You need to meet the following three conditions.

  1. A maven warehouse with publishing authority
  2. At settings.xml Configure the user name and password that you can access this repository
  3. Configure your pom.xml Documents.

After the configuration is successful, you can run MVN clean deploy to publish.

Specifically, for a condition, the simplest way to deploy a local archiva is to publish the Maven repository.

For example, the warehouse address we use is https://maven.ossez.com/ This is the address of our private repository for testing and publishing. Of course, you can also use other servers or commercial services.

How Maven publishes local projects to archiva

At settings.xml You need to configure ID, user name and password.

Here you need to use the real user name and password of archiva.

How Maven publishes local projects to archiva

Modify the pom.xml Documents.

Add the following:

<distributionManagement>
    <repository>
        <id>maven.ossez.com</id>
        <name>Internal Release Repository</name>
        <url>https://maven.ossez.com/repository/internal/</url>
    </repository>
    <snapshotRepository>
        <id>maven.ossez.com</id>
        <name>Internal Snapshot Repository</name>
        <url>https://maven.ossez.com/repository/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

Here is the link address of the warehouse you want to publish to.

How Maven publishes local projects to archiva

Then you can directly run MVN clean deploy for deployment.

The output is:

C:\WorkDir\Repository\cwiki-us-demo\java-tutorials>mvn clean deploy
[INFO] Scanning for projects…
[INFO]
[INFO] ———————-< com.ossez:parent-modules >———————-
[INFO] Building parent-modules 1.0.0
[INFO] ——————————–[ pom ]———————————
[INFO]
[INFO] — maven-clean-plugin:2.5:clean (default-clean) @ parent-modules —
[INFO]
[INFO] — maven-install-plugin:2.4:install (default-install) @ parent-modules —
[INFO] Installing C:\WorkDir\Repository\cwiki-us-demo\java-tutorials\pom.xml to C:\Users\yhu\.m2\repository\com\ossez\parent-modules\1.0.0\parent-modules-1.0.0.pom
[INFO]
[INFO] — maven-deploy-plugin:2.7:deploy (default-deploy) @ parent-modules —
Uploading to maven.ossez.com: https://maven.ossez.com/repos…
Uploaded to maven.ossez.com: https://maven.ossez.com/repos… (9.2 kB at 12 kB/s)
Downloading from maven.ossez.com: https://maven.ossez.com/repos…
Downloaded from maven.ossez.com: https://maven.ossez.com/repos… (331 B at 150 B/s)
Uploading to maven.ossez.com: https://maven.ossez.com/repos…
Uploaded to maven.ossez.com: https://maven.ossez.com/repos… (330 B at 914 B/s)
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 4.573 s
[INFO] Finished at: 2020-04-10T15:13:36-04:00
[INFO] ————————————————————————

C:\WorkDir\Repository\cwiki-us-demo\java-tutorials>

Then you can go to the server to see if your file has been published successfully.

How Maven publishes local projects to archiva

https://www.cwiki.us/display/MAVEN/questions/57938925