使用已发布的工件时,Maven 依赖项解析如何工作?

How does Maven dependency resolution work when using released artifacts?

我有一个多模块 Maven 项目,如下所示:

最终,当我打包发布时,这个库的使用者唯一需要的依赖项是:

我注意到如果我只部署 All 和 JarFile,并且只将这 2 个依赖项添加到一个消费项目并构建我的消费项目,我会收到 maven 构建错误,提示找不到脚本、资源和前端(因为它们' All 的 pom 重新引用)

  1. 当直接使用 All 工件时(在其构建状态),为什么 Maven 会关心它是否无法解析 All pom 的依赖项?这些应该是 All 项目的实施细节吗?
  2. 有什么方法可以配置发布,以便我只需要发布所有 zip 和 JarFile jar 工件?而不是这些“实现细节”工件?

Q1: When using the All artifact directly (in its build state), why does Maven care if it can't resolve the All pom's dependencies? Should those be an implementation detail OF the All project?

Maven 3 解析依赖关系transitively设计

Q2: Is there any way I can configure the release so that I only have to do release the All zip and JarFile jar artifacts? And not these "implementation detail" artifacts?

是的,您可以使用 flatten-maven-plugin to flatten the POM before publishing with the configuration described on usage 页面:

  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
        <!--<version>1.2.2</version>-->
        <configuration>
          <flattenMode>minimum</flattenMode>
        </configuration>
        <executions>
          <!-- enable flattening -->
          <execution>
            <id>flatten</id>
            <phase>process-resources</phase>
            <goals>
              <goal>flatten</goal>
            </goals>
          </execution>
          <!-- ensure proper cleanup -->
          <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>