Deployment Maven-将依赖项部署到远程存储库
我有几个项目有很多maven依赖项。当我调用命令mvndeploy(或它的一些变体)时,我不仅希望将项目本身部署到远程存储库,还希望将其所有依赖项都部署到远程存储库。这可能吗?我在这个网站上看到了很多类似的问题,但我似乎找不到像这样简单的问题。我所看到的其他一切似乎都在期待一些额外的功能。我只想将我的项目及其所有依赖项部署到远程repo。我正在使用maven编译器插件1.5 这是my settings.xml的一个片段。知道我错过了什么吗Deployment Maven-将依赖项部署到远程存储库,deployment,maven,dependencies,Deployment,Maven,Dependencies,我有几个项目有很多maven依赖项。当我调用命令mvndeploy(或它的一些变体)时,我不仅希望将项目本身部署到远程存储库,还希望将其所有依赖项都部署到远程存储库。这可能吗?我在这个网站上看到了很多类似的问题,但我似乎找不到像这样简单的问题。我所看到的其他一切似乎都在期待一些额外的功能。我只想将我的项目及其所有依赖项部署到远程repo。我正在使用maven编译器插件1.5 这是my settings.xml的一个片段。知道我错过了什么吗 <mirrors> <mirror&g
<mirrors>
<mirror>
<!--This is used to direct the public snapshots repo in the
profile below over to a different nexus group -->
<id>nexus-public-snapshots</id>
<mirrorOf>public-snapshots</mirrorOf>
<url>http://{ourServer}/nexus/content/groups/public-snapshots</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://{ourServer}/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>development</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--this profile will allow snapshots to be searched when activated-->
<id>public-snapshots</id>
<repositories>
<repository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public-snapshots</id>
<url>http://public-snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
nexus公共快照
公共快照
http://{ourServer}/nexus/content/groups/public snapshot
关系
*
http://{ourServer}/nexus/content/groups/public
发展
中心的
http://central
真的
真的
中心的
http://central
真的
真的
公共快照
公共快照
http://public-snapshots
假的
真的
公共快照
http://public-snapshots
假的
真的
提前感谢~j您可以从一个干净的本地存储库开始,尝试构建应用程序,如果出现依赖性故障,则将该应用程序部署到公司存储库中。这将确保在构建和部署应用程序之前,应用程序所需的所有依赖项都驻留在公司存储库中 在此之前,您需要将本地存储库配置为镜像
central
和其他知名存储库,以便开源第三方库自动进入远程存储库,而不必手动上载
结果可能是,您可能没有太多需要手动部署的第三方库。假设您的远程存储库(Nexus或Artifactory等)配置正确,下面简单介绍它的工作原理 假设您有一个依赖于
commons日志记录的项目。当Maven作为构建的一部分解析项目的依赖关系时,它会执行以下步骤:
检查本地repo是否有公用记录
李>
如果找到,就完成。继续构建
如果未找到:检查远程回购中的commons日志记录
李>
如果找到,将工件下载到本地repo。完成;继续构建
如果在远程repo中找不到:远程repo请联系central下载公用日志记录。然后Maven可以下载到本地回购协议。完成;继续构建
在这些步骤结束时,commons日志记录
应该在本地和远程repo中,无需进一步操作。如果不是这种情况,则在搜索依赖项时,settings.xml
未配置为连接到远程回购(是否直接与central联系?),或者Nexus未正确配置
----编辑----
下面是我的settings.xml的一段代码,它可以正常工作@当Raghuram建议您启用这两个配置文件时,他给了您一个很好的提示;如果您以某种方式只启用了公共快照
概要文件,那么您的构建将继续直接命中maven central
....
<mirrors>
<!-- redirects all traffic to internal Nexus repo instead of Maven central -->
<mirror>
<id>maven2</id>
<mirrorOf>*</mirrorOf>
<url>http://repository.someCompany.com/maven2RepoOrGroupInNexus</url>
</mirror>
</mirrors>
....
<profiles>
<profile>
<id>repo-profile</id>
<repositories>
<repository>
<id>central</id>
<url>http://gotoNexus</url> <!-- URL is unimportant here -->
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>repo-profile</activeProfile> <!-- important -->
</activeProfiles>
。。。。
马文2
*
http://repository.someCompany.com/maven2RepoOrGroupInNexus
....
回购文件
中心的
http://gotoNexus
真的
每日的
真的
每日的
我提出了以下解决方案,与现有答案相比,该解决方案在解决依赖关系方面看起来不像是反复试验
部署主项目后,您可以调用mvn-Dmdep.copyPom=true dependency:copy dependencies
。这会将项目的所有依赖项传递复制到target/dependency
,包括它们各自的pom文件
然后,您可以迭代所有依赖项,并使用deploy:deploy file
将它们部署到存储库中,例如,使用这样的bash循环:
for pom in target/dependency/*.pom; do mvn deploy:deploy-file -Durl=http://your/repo -Dfile="${pom%%.pom}.jar" -DgeneratePom=false -DpomFile="$pom"
我认为您弄错了,使用maven在您的开发环境中构建它,并将可交付成果(jar、war、ear或osgi包)部署到服务器。您所说的远程存储库到底是什么意思???是服务器吗??或者代码存储库???不。我指的是部署到我的公司远程maven存储库,在命令行中使用“mvn deploy”(或者使用m2Eclipse插件“Run As->maven deploy”),我们使用的是sonatype nexus,如果这有区别的话,尽管我认为mvn安装/mvn deploy是特定于maven的,不是第二个可能的重复。我不是在问mvn安装和mvn部署之间的区别。我已经知道mvn安装“安装”到本地存储库,而mvn部署“部署”到远程存储库。我在寻求一种可能的方法,使用mvn deploy不仅可以将项目部署到远程存储库,还可以将其所有依赖项都部署到远程存储库。您能否详细阐述一下关于“将本地存储库配置为镜像中心存储库和其他知名存储库”的观点?我不知道你这是什么意思。如果我的本地存储库镜像到中央存储库,那么这些库将如何在远程存储库中结束?很抱歉,我对这方面不是很精通……@jacosta。通常,存储库管理器配置为镜像中央存储库和其他所需的存储库,并允许部署特定于项目的工件。后者将使用mvndeploy
完成。因此,如果我镜像中心,并执行mvndeploy