Maven - 将依赖项部署到远程存储库

jac*_*sta 13 deployment dependencies maven

我有一些项目有很多maven依赖项.当我调用命令mvn deploy(或其中的一些变体)时,我不仅要将项目本身部署到远程存储库,还要将其所有依赖项部署到远程存储库.这可能吗?我在这个网站上看到了许多"类似的问题",但我似乎无法找到任何简单的东西.我见过的其他所有东西似乎都期待一些额外的功能.我只是想将我的项目及其所有依赖项部署到远程仓库.我正在使用maven编译器插件1.5

这是我的settings.xml的片段.知道我错过了什么吗?

<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>
Run Code Online (Sandbox Code Playgroud)

在此先感谢
~j

lan*_*tar 8

我提出以下解决方案,与现有答案相比,它看起来更像是试验和错误解决依赖关系.

你可以做的是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"
Run Code Online (Sandbox Code Playgroud)

  • 我认为这是对这个问题的唯一途径和唯一正确答案。这样,如果您不希望包含传递性依赖项,则可以具有很大的灵活性。 (2认同)

Rag*_*ram 2

您可以从一个干净的本地存储库开始,尝试构建您的应用程序,并且对于任何依赖项失败,将该应用程序部署到您的公司存储库。这将确保在构建和部署应用程序之前,应用程序所需的所有依赖项都驻留在公司存储库中。

在此之前,您需要将本地存储库配置为镜像central和其他知名存储库,以便开源第三方库自动进入您的远程存储库,而无需手动上传。

事实证明,您可能没有太多需要手动部署的第三方库。