简体   繁体   English

将我的本地maven存储库同步到Nexus公共存储库

[英]Synchronize my local maven repository to Nexus public repository

I have a local repository which I have been installing jars to for a while from different projects. 我有一个本地存储库,我一直在从不同的项目安装罐子。 We also have a nexus server running, but it does not have all the jars that I have locally. 我们还运行了一个nexus服务器,但它没有我本地的所有jar。

I can try to synchronize jars up to nexus one by one. 我可以尝试逐个将罐子同步到nexus。 But is there a more efficient way to synchronize up to nexus? 但是有更有效的方法来同步到nexus吗? Ideally I would want to execute a single command which would look through all the artifacts in my local repo, and push anything which is missing in nexus. 理想情况下,我想要执行一个命令来查看我本地仓库中的所有工件,并推送nexus中缺少的任何东西。

If a cmd script is the only way, it would be very useful with specific tips around this as well. 如果cmd脚本是唯一的方法,那么对于这方面的具体提示也非常有用。

I might give an update on my progress so far 到目前为止,我可能会更新我的进展情况

echo off
echo MavenSync
setlocal EnableDelayedExpansion
for /R . %%f in (*) do (
  set jarfile=%%~dpnxf
  set name=%%~dpnf
  set pomFile=!name!.pom
  set clientJar=!name!-client.jar

  if [!jarfile:~-4!]==[.jar] (
    echo !jarfile!
    echo !pomFile!
    set repo=http://server/nexus/content/repositories/releases/

    if [!jarfile:~-10!]==[client.jar] (

      rem Handled elsewhere

    ) else (

      if [!jarfile:~-12!]==[SNAPSHOT.jar] (
        set repo=http://server/nexus/content/repositories/snapshots/
      )

      if EXIST !clientJar! (
        echo mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=nexus -Durl=!repo! -DpomFile="!pomFile!" -Dfile="!jarfile!" -Dfiles="!clientJar!" -Dtypes=client-jar -Dclassifiers=bin
      ) else (
        echo mvn deploy:deploy-file -Dpackaging=jar -DrepositoryId=nexus -Durl=!repo! -DpomFile="!pomFile!" -Dfile="!jarfile!"
      )

    )
  )
)

The Maven goal deploy:deploy-file Maven目标deploy:deploy-file

http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

can deploy single artifacts to Nexus (with attached pom, so you don't need to specify the GAV manually). 可以将单个工件部署到Nexus(附带pom,因此您无需手动指定GAV)。

You need to write a script that runs over your local repository, gathers all artifacts and uses above goal to deploy them to Nexus. 您需要编写一个在本地存储库上运行的脚本,收集所有工件并使用上述目标将它们部署到Nexus。

There is no means of doing this easily without writing a custom script. 没有编写自定义脚本,就无法轻松完成此任务。 However, if you have a build which build everything and installs it locally via mvn install then you can deploy it to your nexus by doing mvn deploy . 但是,如果你有创造一切条件,并通过本地安装它构建mvn install ,那么你可以把它做部署到您的Nexus mvn deploy For this to work you need to add a section to your pom for distributionManagement : 为此,您需要在pom中添加一个部分以进行distributionManagement

<distributionManagement>
    <snapshotRepository>
        <id>snapshot.nexus</id>
        <url>${nexus.snapshot.repo}</url>
    </snapshotRepository>
    <repository>
        <id>release.nexus</id>
        <url>${nexus.release.repo}</url>
    </repository>
</distributionManagement>

This will just deploy the latest version of each project however, and not the back history of the older versions. 这只是部署每个项目的最新版本,而不是旧版本的后期历史。

Depending on the version of nexus that you are using it may be possible to copy the contents of your file system. 根据您使用的nexus版本,可以复制文件系统的内容。 Nexus 2 uses file system based storage, so you could potentially compare your .m2 repo with the remote one and copy over the different projects as required. Nexus 2使用基于文件系统的存储,因此您可以将.m2 repo与远程存储进行比较,并根据需要复制不同的项目。 Once the necessary changes were copied across, a reindex of the remote repo should pick up the changes you made. 一旦复制了必要的更改,远程仓库的重新索引应该获取您所做的更改。 Nexus 3 stores the artefacts in a database however, so if you are using that version this wouldn't be possible. 然而,Nexus 3将人工制品存储在数据库中,因此如果您使用的是该版本,则无法实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM