文章目录
- 1.上传所有jar/pom到私服仓库
- 方式1:Nexus手动上传
- 方式2:mvn deploy命令上传
- 2.替换项目中所有pom.xml上传下载地址为私服仓库
- 3.替换本地maven setting.xml配置文件
- 4.下载上传验证操作
- 下载jar出现的问题
- mvn deploy上传jar
- mvn deploy上传执行脚本
1.上传所有jar/pom到私服仓库
方式1:Nexus手动上传
项目在本地下载到所有的依赖了,跑起来了,这时候仓库就有项目所需的所有jar,可以手动上传。
上传示例:
pom拉取不到,需要上传pom
方式2:mvn deploy命令上传
参考文章:【Nexus】切换私服:mvn deploy 上传的时候遇到的4大坑
前提:setting.xml 配置文件已经配置好了,包括:配置私服仓库访问账号密码,指定私服镜像…
这些在下面3有详细介绍。
2.替换项目中所有pom.xml上传下载地址为私服仓库
<id>releases</id>
<name>releases</name>
<url>http://192.168.**36.188**:8081/repository/holdings-releases/</url>
所有pom.xml 替换
<repositories>
<repository>
<id>releases</id>
<name>releases</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>releases</id>
<name>releases</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<distributionManagement>
<repository>
<id>releases</id>
<name>Packaging Release Repository</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Packaging Snapshot Repository</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
</snapshotRepository>
</distributionManagement>
3.替换本地maven setting.xml配置文件
换一个新本地仓库,配置私服仓库访问账号密码,指定私服镜像
前途:nexus私服管理员开放了,仓库的权限、是否允许多次版本更替上传等
<localRepository>D:\Program Files\mavenRepositoryLocal1</localRepository>
<server>
<id>releases</id>
<username>sdfsdf</username>
<password>sdfsdf123</password>
</server>
<server>
<id>snapshots</id>
<username>sdfsdf</username>
<password>sdfsdf123</password>
</server>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>releases</id>
<name>releases</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
<mirrorOf>central</mirrorOf>
</mirror>
4.下载上传验证操作
下载jar出现的问题
切换后,srm-parent 可以下载下来,但是里面引用的基本jar下不下来(比如:swagger、mybatis的jar), 需要同样替换这个pom.xml 里面的配置
<groupId>com.els.srm.v5</groupId>
<artifactId>srm-parent</artifactId>
<version>1.2.1</version>
老是从这个地址下载:svn.51qqt.com
替换srm-parent里面的pom
<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.els.srm.v5</groupId>
<artifactId>srm-parent</artifactId>
<version>1.2.1</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.5.RELEASE</version>
<relativePath />
</parent>
<modules>
<module>srm-core</module>
<module>srm-core-cloud</module>
<module>srm-core-single</module>
</modules>
<name>srm-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR8</spring-cloud.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
<druid.version>1.1.17</druid.version>
<dynamic-datasource.version>3.2.1</dynamic-datasource.version>
<knife4j.version>2.0.4</knife4j.version>
<swagger.version>1.5.22</swagger.version>
<hutool.version>5.6.7</hutool.version>
<shiro.version>1.7.0</shiro.version>
<shiro-redis.version>3.1.0</shiro-redis.version>
<fastjson.version>1.2.75</fastjson.version>
<cglib.version>3.1</cglib.version>
<jwt.version>3.7.0</jwt.version>
<commons.version>2.6</commons.version>
<httpclient.version>4.5.13</httpclient.version>
<google-zxing.version>3.3.0</google-zxing.version>
<!-- Apache Dubbo -->
<dubbo.version>2.7.8</dubbo.version>
<sentinel.version>1.8.2</sentinel.version>
<poi.version>4.1.2</poi.version>
<easyexcel.version>2.1.7</easyexcel.version>
</properties>
<dependencies>
<!-- Lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.sun</groupId>-->
<!-- <artifactId>tools</artifactId>-->
<!-- <version>1.8</version>-->
<!-- <scope>system</scope>-->
<!-- <systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>-->
<!-- </dependency>-->
</dependencies>
<dependencyManagement>
<dependencies>
<!-- spring-cloud -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- spring-cloud-alibaba -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
<version>${sentinel.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>sentinel-dubbo-api</artifactId>
<version>${spring-cloud-alibaba.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>${druid.version}</version>
</dependency>
<!-- 动态数据源 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
<version>${dynamic-datasource.version}</version>
</dependency>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${swagger.version}</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>${hutool.version}</version>
</dependency>
<!--shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring-boot-starter</artifactId>
<version>${shiro.version}</version>
</dependency>
<!-- shiro-redis -->
<dependency>
<groupId>org.crazycake</groupId>
<artifactId>shiro-redis</artifactId>
<version>${shiro-redis.version}</version>
</dependency>
<!-- json -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
<!-- BeanCopier -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>${cglib.version}</version>
</dependency>
<!--JWT -->
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>${jwt.version}</version>
</dependency>
<!--HttpClient -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons.version}</version>
</dependency>
<dependency>
<groupId>com.tencentcloudapi</groupId>
<artifactId>tencentcloud-sdk-java</artifactId>
<version>3.1.62</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
<repository>
<id>releases</id>
<name>releases</name>
<url>http://192.168.36.188:8081/repository/holdings-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>public</id>
<name>public</name>
<url>http://192.168.36.188:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!--<repositories>
<repository>
<id>nexus</id>
<name>Nexus</name>
<url>http://svn.51qqt.com:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>aliyun</id>
<name>aliyun Repository</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>packaging-releases</id>
<name>Packaging Release Repository</name>
<url>http://svn.51qqt.com:8081/nexus/content/repositories/packaging-releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Packaging Snapshot Repository</name>
<url>http://svn.51qqt.com:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>-->
<build>
<plugins>
<!--指定JDK编译版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- 打包跳过测试 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<!-- 避免font文件的二进制文件格式压缩破坏 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>woff</nonFilteredFileExtension>
<nonFilteredFileExtension>woff2</nonFilteredFileExtension>
<nonFilteredFileExtension>eot</nonFilteredFileExtension>
<nonFilteredFileExtension>ttf</nonFilteredFileExtension>
<nonFilteredFileExtension>svg</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.json</include>
<include>**/*.ftl</include>
</includes>
</resource>
</resources>
</build>
</project>
mvn deploy上传jar
上传到SNAPSHOT版本仓库
特别注意:必须全大写,小写、多个字母都不行,会传到releases
release可以改成 allow 允许多次上传版本
在执行 mvn deploy 时,Maven 会自动读取并执行 setting.xml 配置文件中的相关配置,这个也要注意,否则报错
Failed to deploy artifacts: Could not tra
nsfer artifact com.lp.solve:lp-solve:pom:1.0.1 from/to releases (http://192.168.36.188:8081/repository/holdings-releases/): authentication failed for http://192.168.36.188:80
81/repository/holdings-releases/com/lp/solve/lp-solve/1.0.1/lp-solve-1.0.1.pom, status: 401 Unauthorized -> [Help 1]
mvn deploy上传执行脚本
mvn deploy:deploy-file -D groupId=com.pangu.bpmn -D artifactId=pangu-bpmn-common -D version=4.0.3.6-SNAPSHOT -D packaging=jar -D file=C:\Users\DELL\Desktop\bpmn\pangubpm-common\4.0.3.6-SNAPSHOT\pangubpm-common-4.0.3.6-SNAPSHOT.jar -D url=http://192.168.36.188:8081/repository/holdings-snapshots/ -D repositoryId=snapshots