Build nexus private maven private server

Nexus is a powerful Maven warehouse manager, which greatly simplifies the maintenance of its own internal warehouse and the access to external warehouses. With nexus, you can fully control access to and deploy every Artifact in the warehouse you maintain in one place. Nexus is a "out of the box" system. It does not need a database. It uses file system and Lucene to organize data. Nexus uses ExtJS to develop the interface and Restlet to provide complete REST APIs, which are integrated with Eclipse through m2eclipse. Nexus supports WebDAV and LDAP security authentication.

Environmental description

CentOS 6.8, JDK8, Sonatype Nexus, Maven IP: 192.168.50.131 root user operation

Installing Nexus

Premise: JDK8 has been installed and environment variables have been configured

Download Nexus

Download Nexus (here, I use nexus-2.11.2-03-bundle.tar.gz), download address: http://www.sonatype.org/nexus/go/ , we can also enter the following command on the command line of the server to download nexus-2.11.2-03-bundle tar. GZ installation files.

# wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

You can also link to: https://download.csdn.net/download/l1028386804/12523592 Download

Unzip Nexus

# mkdir nexus
# tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C nexus
# cd nexus
# ls
nexus-2.11.2-03 sonatype-work
(One nexus Service, a private library directory)

Edit Nexus

Edit Nexus Directory and port information (default, reserved)

# cd nexus-2.11.2-03
# ls
bin conf lib LICENSE.txt logs nexus NOTICE.txt tmp

Check the directory structure and jetty runs

# cd conf
# vi nexus.properties
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus
# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

Edit nexus script and configure RUN_AS_USER parameter

# vi /usr/local/nexus/nexus-2.11.2-03/bin/nexus
#RUN_AS_USER=

Replace with:

RUN_AS_USER=root

Open port 8081 in firewall

#vi / etc/sysconfig/iptables add

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT

Restart firewall after saving

# service iptables restart

Start nexus

# /usr/local/nexus/nexus-2.11.2-03/bin/nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS usr/local
****************************************
Starting Nexus OSS...
Started Nexus OSS.

Visit nexus

Open in browser: http://192.168.50.131:8081/nexus/

Login to nexus

The default user name is admin and the default password is admin123.

Nexus configuration (after login)

Set administrator mailbox

Menu Administration/Server configuration mailbox service address (if you forget the password, you can retrieve the password through this mailbox)

Set user mailbox

Configure the email address for users to retrieve the password when they forget:

User change password

Warehouse type

  • Group warehouse group: Nexus uniformly manages multiple warehouses through the concept of warehouse group, so that we can directly request the warehouse group in the project to request multiple warehouses managed by the warehouse group;
  • hosted host warehouse: mainly used to publish internal project components or third-party project components (such as purchased commercial components) and components that cannot be obtained from public warehouses (such as JDBC driver of oracle). Proxy warehouse: proxy public remote warehouse;
  • virtual warehouse: used to adapt Maven 1;

The commonly used warehouse types are hosted and proxy.

Description of common types of Hosted warehouse:

  • The release warehouse of the release module in the internal module of releases
  • snapshots is the repository of the internal SNAPSHOT module
  • The 3rd party is a warehouse that the third party relies on. This data is usually downloaded and released by internal personnel

If the local warehouse of Maven project does not have a corresponding dependency package, it will go to the Nexus private server to download it. If the Nexus private server does not have this dependency package, it will go back to the remote central warehouse to download the dependency. These central warehouses are proxies. After downloading the Nexus private server successfully, download it to the local Maven library for project reference.

Set proxy warehouse

Set the proxy repository (Apache Snapshots/Central/Codehaus Snapshots) to allow remote downloading, as shown below.

 

Installation and configuration of Maven local library

Download Maven

To link http://maven.apache.org/download.cgi Download Maven

Configure Maven environment variables

vim /etc/profile

MAVEN_HOME=/usr/local/maven
JAVA_HOME=/usr/local/jdk
CLASS_PATH=$JAVA_HOME/lib
PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
export JAVA_HOME MAVEN_HOME CLASS_PATH PATH

source /etc/profile

Configure local Maven

Copy the configuration file settings. In Maven's conf directory XML, renamed settings Lyz XML, the content after modifying the configuration file is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
 <localRepository>D:/Maven_Repository/.m2/repository</localRepository>
 <interactiveMode>true</interactiveMode>
    <offline>false</offline>
    <pluginGroups>
        <pluginGroup>org.mortbay.jetty</pluginGroup>
        <pluginGroup>org.jenkins-ci.tools</pluginGroup>
    </pluginGroups>
 
 <!--Configure permissions,Use default user-->
 <servers>
  <server>
   <id>nexus-releases</id>
   <username>deployment</username>
   <password>deployment123</password>
  </server>
  <server> 
   <id>nexus-snapshots</id>
   <username>deployment</username>
   <password>deployment123</password>
  </server>
 </servers>
 
    <mirrors>
 
    </mirrors>
 
 <profiles>
  <profile>
     <id>lyz</id>
       <activation>
                    <activeByDefault>false</activeByDefault>
                    <jdk>1.8</jdk>
                </activation>
       <repositories>
     <!-- Private library address-->
        <repository>
      <id>nexus</id>
      <url>http://192.168.50.131:8081/nexus/content/groups/public/</url>
      <releases>
       <enabled>true</enabled>
      </releases>
      <snapshots>
       <enabled>true</enabled>
      </snapshots>
     </repository>
    </repositories>      
    <pluginRepositories>
     <!--Plug in library address-->
     <pluginRepository>
      <id>nexus</id>
      <url>http://192.168.50.131:8081/nexus/content/groups/public/</url>
      <releases>
       <enabled>true</enabled>
      </releases>
      <snapshots>
       <enabled>true</enabled>
        </snapshots>
     </pluginRepository>
    </pluginRepositories>
   </profile>
 </profiles>
 
 <!--activation profile-->
 <activeProfiles>
  <activeProfile>lyz</activeProfile>
 </activeProfiles>

</settings>

Where, in the configuration file

<localRepository>D:/Maven_Repository/.m2/repository</localRepository>

Description the local warehouse is located in D:/Maven_Repository/.m2/repository directory.

The following configuration items in the configuration file.

<url>http://192.168.50.131:8081/nexus/content/groups/public/</url>

Consistent with the link in the figure below:

Configuring Eclipse Maven

 

Project construction and release

First of all, we need to create the POM The following contents are added to the XML file to publish the Jar built by the project to Maven private warehouse

<distributionManagement>
    <repository>
        <id>nexus-releases</id>
        <name>Nexus Release Repository</name>
        <url>http://192.168.50.131:8081/nexus/content/repositories/releases/</url>
    </repository>
    <snapshotRepository>
        <id>nexus-snapshots</id>
        <name>Nexus Snapshot Repository</name>
        <url>http://192.168.50.131:8081/nexus/content/repositories/snapshots/</url>
    </snapshotRepository>
</distributionManagement>

Configuration description

POM in the project In the XML file, if the version is configured as follows:

<version>0.0.1-SNAPSHOT</version>

The corresponding directory after publishing to Maven private warehouse is as follows:

If the version is configured as follows:

<version>0.0.1-RELEASE</version>

The corresponding directory after publishing to Maven private warehouse is as follows.

Complete POM The configuration of the XML file is as follows.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>common-utils-maven</groupId>
    <artifactId>com.chwl.common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <distributionManagement>
        <repository>
            <id>nexus-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.50.131:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>nexus-snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.50.131:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <jdk.version>1.8</jdk.version>
    </properties>
    <dependencies>
       Omitted here....
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                    <encoding>${project.build.sourceEncoding}</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

The specific release steps are as follows:

Right click POM xml->Run as->Maven build->

The private library in the figure above is empty. Right click POM XML - > run as - > Maven build (at this time, the version of pom.xml file is 0.0.1-SNAPSHOT).

After construction,

Note that the project has been built and released to our Maven private warehouse.

At this time, the Release directory in the figure above is empty. At this time, we modify POM The version of XML is 0.0.1-RELEASE. Right click pom.xml again XML - > run as - > Maven build to build the project. The published directory is as follows:

Note that the project has been built and released to our Maven private warehouse.

Finally, we add a third-party Jar dependency to our Maven private warehouse. The specific operations are as follows:

As shown in the figure above, the third-party dependency private warehouse is empty. We upload the third-party dependency to our Maven private warehouse according to the following steps.

 

As shown in the figure above, the third-party dependency has been uploaded to our Maven private warehouse.

 

https://blog.csdn.net/yp090416/article/details/108143343

https://mp.weixin.qq.com/s/6IIaTUTqNLjB38KvOP1OsA Original glacier Technology

https://mp.weixin.qq.com/s/a4PcXjqItFZU3Spgeli_Ng Core configuration of enterprise maven

 

Posted by Goafer on Thu, 12 May 2022 10:22:45 +0300