简单的网站设计案例,上海浦东做网站的公司,百度安装app下载免费,专门做产品推广ppt的网站目录 1 现状2 当前解决3 更好的解决3.1 下载 Maven localRepository 工具包3.2 上传本地 localRepository 包3.3 清理 localRepository 中指定后缀的文件 1 现状
在使用 Maven 时#xff0c;我们可能会经常与本地仓库和私服仓库打交道。
例如对于本地仓库#xff0c;因为某… 目录 1 现状2 当前解决3 更好的解决3.1 下载 Maven localRepository 工具包3.2 上传本地 localRepository 包3.3 清理 localRepository 中指定后缀的文件 1 现状
在使用 Maven 时我们可能会经常与本地仓库和私服仓库打交道。
例如对于本地仓库因为某些文件位拉取到会在本地仓库的项目目录下产生 .lastUpdated 后缀的文件有时编译项目时为了更快的重新再次拉取正确的包还不得不手动清除这些文件。
而对于私服如果是公司自己的私服不巧的是公司的 Maven 私服例如 Nexus又无法访问外网在公司内网使用公司私服编译项目时我们期望上传上自己的依赖包此时往往是很多的文件就不得不手动一个一个上传如果动手能力比较强的可以根据对应环境编写一个小脚本执行。
2 当前解决
如果是在 Linux 服务可以通过如下的 Shell 命令清除本地仓库下所有的 .lastUpdated 后缀的文件目录但如果是 Windows 系统或者其他不支持 Shell 的系统就不得不查找对应系统的查找和清除文件夹的命令了。
find ~/.m2/repository/ -regex .*\.lastUpdated | xargs dirname | xargs rm -rf对于向自己私服发布包的情况一般有两种方式第一种是通过Maven 私服的管理页面提供的功能进行上传第二种是通过 mvn deploy 命令上传。
对于本地系统安装了 maven 的可以使用 Maven 命令上传命令如下
mvn -s /Users/yoreyuan/code/yore/settings.xml deploy:deploy-file \
-Dfile/Users/yoreyuan/.m2/xxx/1.0.0/xxx-1.0.0.jar \
-DpomFile/Users/yoreyuan/.m2/xxx/1.0.0/xxx-1.0.0.pom \
-Durlhttp://nexus.yore.cn/repository/maven-releases \
-DrepositoryIdyore_nexus -X -Dpackagingjar如果顺利的话非常清爽的成功了但紧接着可能会遇到如下的问题 【问题 1】如果包非常多上面的命令一个一个执行简直是噩梦。对于会 Shell或 Python 的则可能想到编写一个脚本。但如果不巧的是使用的是 Windows 系统的 Java 开发者其开发环境没有 Shell 和 Python 如何上传呢最终可能在公司找了一个Linux服务器配上环境把自己的本地的Maven localRepository 打包上传到公司服务器上然后又编写脚本执行脚本循环上传这些包最终费了好大劲终于上传上了短暂的开心后突然却又遇到了下面的问题。
【问题 2】使用公司的私服来编译自己项目时竟然报缺包。经过排查发现上面的命令仅仅上传了 jar 包例如 xxx-tests.jar、xxx-sources.jar、xxx-test-sources.jar 和 xxx-linux-x86_64.exe 等都没有上传对脚本熟悉的可能马上花一些时间脚本就改好了对于脚本不太熟悉的 java 开发者可能就在一次一次报错中找到缺失的包通过 Nexus 页面上传了终于可以编译过了。自己非常非常的开心于是把自己历尽千辛万苦实践可行的方法分享给公司其他小伙伴。 【问题 3】可运行了一段时间在某天晚上流水线出包的时候突然自己的项目编译报错了竟然提示有个包神奇的又找不到了。其实最苦恼还有包编译出来了运行却失败了一通排查竟发现依赖的某个包的版本使用的却是另外一个版本的包。望着一串串流水线异常日志此时终于又陷入了沉思。
经过一段时间的排查终于发现不知道是哪个大聪明也许是自己从新上传了某个依赖在上传某个依赖的时候没有上传项目的 pom 文件而是直接勾选了 Nexus Upload 页面的 Generate a POM file with these coordinates导致私服上项目中很重要的依赖的 pom 中依赖信息缺失。此时如果在没有显示引用依赖的情况下可能会从其他依赖集成过来某个包如果包存在就顺利编译成功了但可能运行的时候发现类缺失、方法缺失等等异常而如果包不存在则直接在流水线编译的时候就异常了。 所以面对这种情况排查私服上 pom 文件如果有缺失的手动删除单独上传完整的 pom 文件如下图jar 上传后千万不要勾选 Generate a POM file with these coordinates然后再上传一次 pom 文件此时 GAV 信息是灰色的直接上传即可。
3 更好的解决
一路走来坑坑洼洼磕磕绊绊细节那么多怎么保证身边其他同事不会一不小心再犯同样的错呢有没有更好的解决方案呢
答案肯定是有滴下面来介绍一个实用的工具 tools-maven-localRepository这个项目是使用 go 语言编写的一个 Maven localRepository 工具。支持的操作系统有 Linux、Windows、Mac OS可以直接指定本地 localRepository 路径即可将此路径下的所有包上传到 Maven 私服上也支持清理 localRepository 中指定后缀的文件。
环境要求系统中需要安装 JDK 和 Maven对于 Java 开发开发环境中一般都有如果没有需要先安装配置下
3.1 下载 Maven localRepository 工具包
使用也非常简单访问 tools-maven-localRepository/releases/tag/v1.0.0 下载编译好的工具包 tools_maven_localRepository-bin.zip解压解压后目录如下
tools_maven_localRepository
├── config.yaml.template # 应用的配置文件模板
├── darwin-amd64 # Mac OS
│ └── tools_localRepo
├── linux-amd64 # linux OS
│ └── tools_localRepo
├── readme.md
├── settings.xml.template # Maven settings.xml 配置文件模板
└── windows-amd64 # Windows OS└── tools_localRepo拷贝 settings.xml.template 为 settings.xml简单配置如下信息主要是 servers 中的私服账号信息
?xml version1.0 encodingUTF-8?
settings xmlnshttp://maven.apache.org/SETTINGS/1.2.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd!--localRepository/home/yore/.m2/repository/localRepository--pluginGroups/pluginGroupsproxies/proxiesserversserveridyore_nexus/idusernameyore/usernamepassword123456/password/server/serversmirrorsmirroridyore_nexus/idmirrorOf*/mirrorOfurlhttp://nexus.yore.cn/repository/maven-public/url/mirror/mirrorsprofilesprofileidyore_nexus/idrepositoriesrepositoryidyore_nexus/idnameyore nexus/nameurlhttp://nexus.yore.cn/repository/maven-public/urlreleasesenabledtrue/enabled/releasessnapshotsenabledtrue/enabled/snapshots/repository/repositories/profile/profilesactiveProfilesactiveProfileyore_nexus/activeProfile/activeProfiles
/settings
3.2 上传本地 localRepository 包
拷贝 config.yaml.template 为 config.yaml简单配置如下信息
# 是否输出项目的 debug 信息
verbose: false
logLevel: INFO# Maven localRepository 本地路径
localRepository: ~/.m2/repositorydeploy:enable: truecommandName: /usr/local/bin/mvn# Alternate path for the user settings filesettingXml: ~/.m2/settings.xml# The ID of the repositoryid: yore_nexus# The URL of the repository mavenurl: http://nexus.yore.cn/repository/maven-releases# Output maven debugging informationdebug: false# The list of file suffixes to be ignoredexcludeSuffixs:- .DS_Store- .asc- .lastUpdated- .md5- .repositories- .sha1- .sha256- .sha512- .xmlclean:enable: false主要关注如下几个配置
localRepository Maven localRepository 本地路径deploy.enable 启用 deploydeploy.settingXml Maven 的 setting.xml 配置路径deploy.id 私服仓库的 ID需要与 setting.xml 中配置的私服账号 ID 一致deploy.url 私服仓库的地址
执行如下命令开始上传
./tools_localRepo --config ./config.yaml如果需要输出项目更详细的信息可以将 verbose 设置为 true如果需要输出 Maven 执行的更详细的信息可以将 deploy.debug 设置为 true。
3.3 清理 localRepository 中指定后缀的文件
拷贝 config.yaml.template 为 config.yaml简单配置如下信息
# 是否输出项目的 debug 信息
verbose: false
logLevel: INFO# Maven localRepository 本地路径
localRepository: ~/.m2/repositorydeploy:enable: falseclean:# If it is in cleaning mode, the list of file suffixes that will be cleaned upenable: truesuffixs:- .DS_Store- .lastUpdated主要关注如下几个配置
localRepository Maven localRepository 本地路径deploy.enable 关闭 deployclean.enable 启用 cleanclean.suffixs 需要清理 localRepository 中的后缀文件列表
执行如下命令开始上传
./tools_localRepo --config ./config.yaml同样如果需要输出项目更详细的信息可以将 verbose 设置为 true如果需要输出 Maven 执行的更详细的信息可以将 deploy.debug 设置为 true。