如何在具有父 pom 时将工件正确部署到 nexus?

How to correctly deploy artifact to nexus when it has parent pom?

我在将工件部署到 Nexus 时遇到问题。我正在使用来自sonatype的maven和nexus-staging-maven-plugin。我的项目结构是: 带有 2 个子模块 B 和 C 的父 A。 在 B 的 pom.xml 中,我声明了如下所示的插件(当然还有存储库等):

   <plugin>
    <groupId>org.sonatype.plugins</groupId>
    <artifactId>nexus-staging-maven-plugin</artifactId>
    <version>1.5.1</version>
    <executions>
      <execution>
        <id>default-deploy</id>
        <phase>deploy</phase>
        <goals>
          <goal>deploy</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <nexusUrl>http://nexus.intranet:8081/repository/myrepo/</nexusUrl>
      <serverId>nexus</serverId>
      <skipStaging>true</skipStaging>
    </configuration>
  </plugin>

我的工件正在正确部署到文件夹 com/myorg/B/1.1.5/ 的 nexus 并且存在 jar 和 B 的 pom.xml 和 sha 文件。 问题是,当我添加到另一个项目依赖项 B 时,这个项目试图在关系 A(B 的父 pom)中找到。我是否也应该将父 pom.xml 部署到我的关系中?我应该如何在 B pom.xml 中配置我的插件才能正确执行此操作?

您还必须始终部署所有父 POM,因为没有父 POM,Maven 无法读取 POM。

因此在多模块项目中,您应该将包括父模块在内的所有模块部署到同一个地方。

我已经解决了我的问题。 答案是肯定的——如果你想在某个地方使用子模块作为依赖项,你也需要在存储库中拥有它的父 pom。 我通过从 sonatype 添加到我的父 pom 暂存插件来解决问题,以便也可以将父 pom 部署到 nexus。比构建成功,现在我可以使用我的子工件(在我的问题中命名为 B)作为另一个项目的依赖项。