maven构建升级413问题

446 阅读2分钟

目录

问题描述:

排查过程:

解决方案:


以下内容摘自雪球,在公司内部的docs上的内容总结,部分隐私信息已经处理改动


xueqiu.com/

直接我球docs粘过来的,我不用写两份,欢迎投递简历:github.com/singgel 

问题描述:

在一次maven自动构建-发布-升级的过程中,出现maven的413错误

使用的过程:maven自动构建发布

排查过程:

报错内容如下:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project webWeb: Failed to deploy artifacts: Could not transfer artifact com.test:webWeb:war:1.0-20151009.085440-1 from/to snapshots (repo.snowballfinance.com/artifactory…): Failed to transfer file: repo.snowballfinance.com/artifactory…. Return code is: 413, ReasonPhrase: Request Entity Too Large. -> [Help 1]

首先根据内容可以看出,发布的内容是个war包,而且这个war在本地查看大小为42.5MB:

1.按照项目的角度在maven的私服仓库里面,不应该有业务的服务

2.按照报错的意思理解是上传的文件太大,被服务器拒绝

解决方案:

1.扩大maven的私服仓库的上传限制:

nexus服务使用了nginx做反向代理,jar包的大小超过了nginx所允许的范围。修改nginx.conf配置,将client_max_body_size设置为一个较大的值:

| ```html server { client_max_body_size 10M; listen 80; server_name localhost; location / { proxy_pass http://127.0.0.1:8000/; } }

| ---------------------------------------------------------------------------------------------------------------------------------------------- |

2.本地限制上传(二选一):

* 限制上传的项目

在不需要deploy的项目里的pom.xml添加

| ```html
<properties>      <maven.deploy.skip>true</maven.deploy.skip> </properties>
``` |
| --------------------------------------------------------------------------------------- |

 

* 限制上传的内容

在要限制上传的项目的pom.xml文件plugins里添加

| ```html
<!-- deploy时只上传jar包到远程仓库的配置 -->     	<plugin>     		<artifactId>maven-deploy-plugin</artifactId>     		<executions> 				 <execution> 				 	<id>default-deploy</id> 		            <phase>deploy</phase> 		            <goals> 		            	<goal>deploy</goal> 		            </goals> 		            <!-- skip默认deploy插件的执行 --> 				 	<configuration> 				 		<skip>true</skip> 				 	</configuration> 				 </execution> 				 <execution> 				 	<id>deploy-file</id> 				 	<phase>deploy</phase> 				 	<goals> 				 		<goal>deploy-file</goal> 				 	</goals> 				 	<configuration> 				 		<!-- 开发阶段上传到snapshot仓库,上线阶段上传到release仓库 --> 				 		<repositoryId>${project.distributionManagement.snapshotRepository.id}</repositoryId> 				 		<url>${project.distributionManagement.snapshotRepository.url}</url> 				 		<file>${project.build.directory}/${project.artifactId}-interface.jar</file>  						<groupId>${project.groupId}</groupId> 				 		<artifactId>${project.artifactId}</artifactId> 						<version>${project.version}</version> 				 		<classifier>interface</classifier> 				 	</configuration> 				 </execution>     		</executions>     	</plugin>
``` |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

目前configuration的这部分没有做到自动识别,因此在SNAPSHOT快照版本和RELEASE版本切换时麻烦手动一下,后续有新的进展会同步

 

 

 

 

 

 

 

 

 

 

 

 

附赠其他问题解析:

maven编译时,报错:

| ```
Failure to find org.jfrog.maven.annomojo:maven-plugin-anno:jar:1.4.0 in http://myrepo:80/artifactory/repo  was cached in the local repository, resolution will not be reattempted until the update interval of MyRepo has elapsed or updates are forced -> [Help 1] 
``` |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

原因:服务器之前是使用的官方maven库拉取依赖,本地已经存在jar包,配置了nexus仓库之后,跟之前本地的jar包产生了冲突。\
解决方法:删除\~/.m2/repository目录下对应的jar包。 或者干脆从新download一遍所有jar包。

| ```html
mvn clean install -U
``` |
| -------------------------------- |

\-U表示强制更新所有依赖

\--------------------

拉取到本地的第三方库,只有lastUpdated文件,却不见pom和jar文件:\
本地报错:

| ```
[WARNING] The POM for xxx.jar is missing, no dependency information available
``` |
| ------------------------------------------------------------------------------------- |

库的groupId改了,而且它还删除了maven中央仓库的groupId对应的包,maven找不到对应的pom和jar包,就只会创建lastUpdated文件。