Nexus private server setup - windows version

nexus official download address https://www.sonatype.com/products/repository-oss-download

Step 1: Nexus itself is a service. After decompressing the downloaded compressed package, you will see two folders

Step 2: open the command line, switch to the nexus-3.20.1-01/bin directory, and you will see the Nexus startup file nexus.exe

Step 3: enter the command nexus.exe/run and press enter to start the nexus service. The following message indicates that the startup is successful

You can modify some configurations of nexus. There are two configuration files:

  • nexus.vmoptions under nexus-3.20.1-01/bin directory,

  • In nexus-default.properties under nexus-3.20.1-01/etc directory, you can modify the port number (8081 by default)

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

nexus.hazelcast.discovery.isEnabled=true

Step 4: visit the browser address localhost:8081 to see the welcome page of nexus. If you enter for the first time, you will be prompted to log in

Step 5: after logging in, click the Browse menu to see the default warehouse of nexus

nexus has four warehouse types:

  • Hosted: the hosted warehouse is used to deploy the company's internal distribution packages to the warehouse, and then other people in the company can download and rely on it from the hosted warehouse
  • Proxy: proxy warehouse. This warehouse is not used for internal publishing and deployment. It is used to proxy various warehouses outside the company, such as java.net, codehaus, jboss, etc. the most important thing is that it proxy the central warehouse outside the company. However, you can also modify the nexus connection to Alibaba cloud image warehouse, and Alibaba cloud to connect to the central warehouse.
  • Group: warehouse group is actually a virtual warehouse group composed of various host warehouses and agent warehouses. As long as our project configuration depends on a warehouse group, it is equivalent to automatically connecting various warehouses corresponding to the warehouse group.
  • Virtual: virtual warehouse

nexus default warehouse explanation:

  • maven central: This is the agent warehouse, the agent maven central warehouse
  • Maven releases: this warehouse is a host warehouse used to deploy release packages (similar to 1.0.0, release means that your project has been fully tested, unit tested, integrated tested, QA tested and used in the production environment) to this warehouse for other colleagues to rely on and use in the production environment
  • Maven snapshots: this warehouse is a host warehouse, which is used to deploy the release package of the company's internal snapshot version to this warehouse (if your project is still under development and the test is not over, but other colleagues in the company are also developing some projects and need to rely on your package for development, testing and joint commissioning. At this time, the version of your project is a version similar to 1.0.0-SNAPSHOT), which can be used by other colleagues during development and testing
  • Maven public: warehouse group. All the above release warehouses are in this warehouse group

Step 6: click the cpoy button after the warehouse to view the url of the warehouse, which is used when maven configures the warehouse

Step 7: click the configure button at the top of the website to create, modify, manage warehouses and manage users. For example, you can replace the agent warehouse of Maven central warehouse with Alibaba cloud warehouse

Step 8: the basic private server is set up. If you need other configurations, you can configure them according to your needs. You can test the private server locally and configure it in settings.xml

<!--Specify the authentication information to use when connecting to a specific server. Note server of id To be with mirror of id, repository of id agreement-->
<!--The user name and password here can be nexus In user management, there are two users by default amdin anonymous-->
<servers>
    <server>
        <id>nexusmy</id>
        <username>admin</username>
        <password>admin123456</password>
    </server>
</servers>
<!--Configure the image and use our private server to proxy all remote warehouses-->
<mirrors>
    <mirror>
		<id>nexusmy</id>
		<mirrorOf>*</mirrorOf>
		<name>nexus-public</name>
		<url>http://localhost:8081/repository/maven-public/</url>    
    </mirror> 
</mirrors>

<!--Configure private server warehouse-->
<profiles>
    <profile>
		<id>alwaysActiveProfile</id>    
		<repositories>
			<repository>
				<id>nexusmy</id>
				<name>Team Maven Repository</name>
				<url>http://localhost:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>nexusmy</id>
				<name>Team Maven Repository</name>
				<url>http://localhost:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
  </activeProfiles>

Step 9: execute the mvn command to see the plug-in downloaded from the private server, such as mvn clean

Step 10: Test maven deployment

  1. Add the following configuration in pom.xml
<distributionManagement>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Central snapshots Repository</name>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>releases</id>
        <name>Central-releases Repository</name>
        <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
</distributionManagement>
  1. Add the following configuration in settings.xml
<servers>
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123456</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123456</password>
    </server>
</servers>
  1. Execute mvn deploy, and you can see that our snapshots version jar package has been uploaded to the Maven snapshots repository of the private server

Tags: Maven

Posted on Thu, 02 Dec 2021 20:57:08 -0500 by woolyg