linux下maven私服nexus搭建及配置

安装

1.下载nexus-3.13.0-01-unix.tar.gz到/user/lcoal/src目录

nexus3需要jdk8

2.解压缩

nexus的工作目录默认为sonatype-work,路径与nexus安装目录同级,所以在外边添加一层父目录
mkdir /usr/local/nexus
tar -xzvf nexus-3.13.0-01-unix.tar.gz
mv nexus-3.13.0-01 /usr/local/nexus

3.编辑配置,编辑nexus.vmoptions

cd /usr/local/nexus-3.13.0-01/bin
vim nexus.vmoptions
vm参数修改为
-Xms256M
-Xmx256M
-XX:MaxDirectMemorySize=512M
Nexus默认的端口是8081,可以在etc/nexus-default.properties配置中修改。

4.启动

cd /usr/local/nexus-3.13.0-01/bin
./nexus start
查看日志
tail -f /usr/local/nexus/sonatype-work/nexus3/log/nexus.log

5.浏览器打开管理页面

http://ip:8081/
用户名:admin
密码:admin123

nexus配置

1.创建用户

2.创建仓库

默认仓库介绍
1)maven-central: maven中央库,默认从https://repo1.maven.org/maven2/拉取jar
2)maven-releases: 私库发行版jar
3)maven-snapshots:私库快照(调试版本)jar
4)maven-public: 仓库分组,把上面三个仓库组合在一起对外提供服务,在本地maven基础配置settings.xml中使用。
Nexus默认的仓库类型有以下四种:(上面的名字可以随便取,关键是它对应的是什么仓库类型)
1)group(仓库组类型):又叫组仓库,用于方便开发人员自己设定的仓库;
2)hosted(宿主类型):内部项目的发布仓库(内部开发人员,发布上去存放的仓库);
3)proxy(代理类型): 从远程中央仓库中寻找数据的仓库(可以点击对应的仓库的Configuration页签下Remote Storage Location属性的值即被代理的远程仓库的路径);
4)virtual(虚拟类型): 虚拟仓库(这个基本用不到,重点关注上面三个仓库的使用);
Policy(策略):表示该仓库为发布(Release)版本仓库还是快照(Snapshot)版本仓库;

主要创建3个仓库
proxy仓库 作用是去远程拉取jar包
hosted仓库 作用是存放本地上传的三方jar包
group仓库 作用是将上面来个放到这个组里,进行统一管理

创建proxy仓库
类型maven2(proxy),proxy地址为阿里云仓库地址http://maven.aliyun.com/nexus/content/groups/public

创建两个hosted仓库:release,snaphost
类型为maven2(hosted)

创建group
类型为maven2(group),包含上面三个创建的仓库

maven配置

setting.xml配置

<?xml version="1.0"?>
<settings>
    <localRepository>/Users/liufq/.m2/repository</localRepository><!--需要改成自己的maven的本地仓库地址 -->
    <servers>
        <server>
            <!--jar上传时候进行的验证,id对应的pom中distributionManagement配置的id -->
            <id>releases</id>
            <username>xy</username>
            <password>xy</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>xy</username>
            <password>xy</password>
        </server>
    </servers>

    <mirrors>
        <mirror>
            <id>nexus</id>
            <name>nexus</name>
            <!--镜像采用配置好的组的地址 -->
            <url>http://192.168.1.102:8081/repository/xy-group/</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>

    <profiles>
        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>

        <profile>
            <id>nexus-repo</id>
            <!-- 远程仓库列表 -->
            <repositories>
                <repository>
                    <id>nexus-repo</id>
                    <name>Nexus Central</name>
                    <!-- 指向镜像的URL -->
                    <url>http://192.168.1.102:8081/repository/xy-group/</url>
                    <layout>default</layout>
                    <!-- 表示可以从这个仓库下载releases版本的构件 -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <!-- 表示可以从这个仓库下载snapshot版本的构件 -->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <!-- 插件仓库列表 -->
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-repo</id>
                    <name>Nexus Central</name>
                    <url>http://192.168.1.102:8081/repository/xy-group/</url>
                    <layout>default</layout>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <!--需要激活 <profile>中的ID才生效 -->
        <activeProfile>nexus-repo</activeProfile>
        <activeProfile>jdk-1.8</activeProfile>
    </activeProfiles>

</settings>  

pom.xml配置

<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>com.pt</groupId>
    <artifactId>pt-parent</artifactId>
    <version>1.0.0-RELEASE</version>
    <packaging>pom</packaging>
    <name>pt-parent</name>

    <properties>
        <project.groupId>com.pt</project.groupId>
        <project.version>1.0.0-RELEASE</project.version>
        <junit.version>4.12</junit.version>
        <spring.version>4.3.9.RELEASE</spring.version>
        <logback.version>1.2.3</logback.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>pt-utils</module>
        <module>pt-db</module>
        <module>pt-seqGenerator</module>
        <module>pt-msg</module>
    </modules>

    <dependencyManagement>
        ...
    </dependencyManagement>

    <!-- 打包上传配置 -->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://192.168.1.102:8081/repository/xy-release/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal snapshots</name>
            <url>http://192.168.1.102:8081/repository/xy-snaphost/</url>
        </snapshotRepository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.10.4</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <aggregate>true</aggregate>
                    <charset>UTF-8</charset>
                    <docencoding>UTF-8</docencoding>
                </configuration>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <executions>
                    <execution>
                        <id>deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

测试

下载jar包
mvn clean install -Dmaven.test.skip=true 
打包上传
mvn clean deploy -Dmaven.test.skip=true 

猜你喜欢

转载自www.cnblogs.com/assembly--/p/12340389.html