maven私服配置和使用

安装nexus maven私服

下载

资源

阿里云和硬盘
nexus-3.30.0-01-win64.zip
安装路径
E:\Program Files (x86)\nexus\nexus-3.30.0-01-win64\sonatype-work\nexus3
默认密码
E:\Program Files (x86)\nexus\nexus-3.30.0-01-win64\sonatype-work\nexus3\admin.password

把密码复制出来,账号admin。

创建阿里云仓库:

Repository-->Repositories-->Create repository-->maven2(proxy)

image-20210327193528622

image-20210327193602790

image-20210327193742501

配置仓库组(默认已有一个maven-public)
Repository-->Repositories-->Create repository-->maven2(group)

image-20210327194242582

注:注意仓库顺序。maven查找依赖时会依次遍历仓库组中的仓库。

创建角色

我的配置

image-20210327194730287

nx-admin被占用,我该为nx-yyh

image-20210327194823041

创建用户
Security-->Users-->Create

image-20210327194938008

创建第三方库

方便自己上传jar包

路径

Repository-->Repositories-->Create repository-->maven2(hosted)

image-20210327195830480

修改仓库组
Repository-->Repositories-->Create repository-->maven2(group)

image-20210327200021236

image-20210327200058913

创建spring-plugin、spring和JBoss

镜像来自于网络,可以参考阿里云镜像

image-20210328004332401

maven配置修改

image-20210328004739145

image-20210328004929539

image-20210328005154789

我的配置
setting.xml
<?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">

<!--	激活两个配置一个是jdk 一个是私服配置-->
  <activeProfiles>
    <activeProfile>my-nexus</activeProfile>
	<activeProfile>jdk-1.8</activeProfile>
  </activeProfiles>
 
  <localRepository>D:\programfile\MavenWM</localRepository>

  <servers>
	  <!--第一个nexus-xu要和下面的mirror中的id一致,代表拉取是也需要进行身份校验-->
	  <server>
		  <id>nexus-yyh</id>
		  <username>admin</username>
		  <password>admin123</password>
	  </server>
	  <server>
		  <!--对应项目里面的-->
		  <id>releases</id>
		  <username>admin</username>
		  <password>admin123</password>
	  </server>
	  <server>
		  <id>snapshots</id>
		  <username>admin</username>
		  <password>admin123</password>
	  </server>
  </servers>

	<mirrors>
		<mirror>
			<id>nexus-yyh</id>
			<name>internal nexus repository</name>
			<!--镜像采用配置好的组的地址-->
			<url>http://192.168.50.39:8081/repository/my-group/</url>
			<mirrorOf>*</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>my-nexus</id>
		  <!-- 远程仓库列表 -->
		  <repositories>
			  <repository>
				  <id>nexus-yyh</id>
				  <name>Nexus Central</name>
				  <!-- 虚拟的URL形式,指向镜像的URL-->
				  <url>http://192.168.50.39:8081/repository/my-group/</url>
				  <layout>default</layout>
				  <!-- 表示可以从这个仓库下载releases版本的构件-->
				  <releases>
					  <enabled>true</enabled>
				  </releases>
				  <!-- 表示可以从这个仓库下载snapshot版本的构件 -->
				  <snapshots>
					  <enabled>true</enabled>
				  </snapshots>
			  </repository>
		  </repositories>
		  <!-- 插件仓库列表 -->
		  <pluginRepositories>
			  <pluginRepository>
				  <id>nexus-yyh</id>
				  <name>Nexus Central</name>
				  <url>http://192.168.50.39:8081/repository/spring-plugin/</url>
				  <layout>default</layout>
				  <snapshots>
					  <enabled>true</enabled>
				  </snapshots>
				  <releases>
					  <enabled>true</enabled>
				  </releases>
			  </pluginRepository>
		  </pluginRepositories>
	  </profile>


  </profiles>


</settings>
项目配置

重点是distributionManagement配置

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <name>Nexus Release Repository</name>
            <url>http://192.168.50.39:8081/repository/my-group/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Nexus Snapshot Repository</name>
            <url>http://192.168.50.39:8081/repository/my-group/</url>
        </snapshotRepository>
    </distributionManagement>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.3.7.RELEASE</version>
                <configuration>
                    <mainClass>com.example.demo.DemoApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值