How Maven publishes local projects to Archiva

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

In order to publish some private projects to the internal Archiva of the company, how to use Maven to publish.


 

This is actually relatively simple.

You need to meet the following 3 conditions.

  1. A Maven repository with publishing rights
  2. Configure the username and password you can access to this repository in settings.xml
  3. Configure your pom.xml file.

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

Specifically, for a conditional maven repository with publishing rights, the easiest way is to deploy a local archiva.

For example, the warehouse address we use is https://maven.ossez.com/ , which is an address where we test and publish a private warehouse. Of course, you can also use other servers or commercial services.

Configure the server in settings.xml, here you need to configure id and username and password.

Here you need to use the real username and password for publishing archiva.

Modify the project's pom.xml file.

Add the following content:

	<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.

Then you can directly run mvn clean deploy to deploy.

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/repository/internal/com/ossez/parent-modules/1.0.0/parent-modules-1.0.0.pom
Uploaded to maven.ossez.com: https://maven.ossez.com/repository/internal/com/ossez/parent-modules/1.0.0/parent-modules-1.0.0.pom (9.2 kB at 12 kB/s)
Downloading from maven.ossez.com: https://maven.ossez.com/repository/internal/com/ossez/parent-modules/maven-metadata.xml
Downloaded from maven.ossez.com: https://maven.ossez.com/repository/internal/com/ossez/parent-modules/maven-metadata.xml (331 B at 150 B/s)
Uploading to maven.ossez.com: https://maven.ossez.com/repository/internal/com/ossez/parent-modules/maven-metadata.xml
Uploaded to maven.ossez.com: https://maven.ossez.com/repository/internal/com/ossez/parent-modules/maven-metadata.xml (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.

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

Guess you like

Origin www.cnblogs.com/huyuchengus/p/12677506.html