微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在不使用“硬”依赖项的情况下在程序集中包含另一个模块的构建输出?

如何解决如何在不使用“硬”依赖项的情况下在程序集中包含另一个模块的构建输出?

我的(非常简化的)Maven 项目,包括所需的输出文件如下:

.
│   pom.xml
├───db-delivery
│   │   assembly.xml
│   │   db-delivery-info.txt
│   │   pom.xml
│   └───target
│           db-delivery-1.0.0-SNAPSHOT.zip
└───delivery
    │   assembly.xml
    │   delivery-info.txt
    │   pom.xml
    └───target
            delivery-1.0.0-SNAPSHOT.zip

delivery-1.0.0-SNAPSHOT.zip内容如下所示(db-delivery ZIP 文件仅包含 db-delivery-info.txt):

.
│   delivery-info.txt
└───db
        db-delivery-info.txt

如果我执行 mvn verify 一切正常。但是由于从msa:deliverymsa:db-delivery:zip的依赖,一些需要依赖解析的“快速”Maven目标无法执行,例如mvn dependency:treemvn org.basepom.maven:duplicate-finder-maven-plugin:check。问题是,除非涉及到package阶段,否则db-delivery的ZIP文件在反应器中是不可用的,这导致Could not find artifact msa:db-delivery:zip:1.0.0-SNAPSHOT一旦目标在{{ 1}}。

我尝试将依赖项类型从 delivery 更改为 zip。这样“快速”目标就可以工作,但是如果我再次进行“完整”构建(pom),我的 delivery.zip 不包含 db-delivery.zip 的内容(尽管后者已构建为好吧)但只有一个 mvn verify 文件

有没有办法将 db-delivery-1.0.0-SNAPSHOT.pom 的 ZIP 工件放入 db-delivery 程序集而不直接对其具有依赖项(delivery 类型)?只要我确保模块 zipdb-delivery 之前构建(例如具有 delivery 类型的依赖项),必要的文件在需要时可用,所以从技术上讲,这应该有可能。

根(聚合器和父 POM):

pom

模块交付

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>msa</groupId>
  <artifactId>root</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>delivery</module>
    <module>db-delivery</module>
  </modules>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>3.3.0</version>
          <configuration>
            <appendAssemblyId>false</appendAssemblyId>
            <descriptors>
              <descriptor>assembly.xml</descriptor>
            </descriptors>
          </configuration>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>msa</groupId>
    <artifactId>root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>delivery</artifactId>
  <packaging>pom</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>msa</groupId>
      <artifactId>db-delivery</artifactId>
      <version>${project.version}</version>
      <type>zip</type><!-- using pom makes `mvn dependency:tree` work but creates wrong ZIP file content -->
    </dependency>
  </dependencies>
</project>

模块db-delivery

<assembly>
  <id>delivery-zip</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <files>
    <file>
      <source>delivery-info.txt</source>
    </file>
  </files>

  <dependencySets>
    <dependencySet>
      <outputDirectory>db</outputDirectory>
      <unpack>true</unpack>
      <useProjectArtifact>false</useProjectArtifact>
      <includes>
        <include>msa:db-delivery</include>
      </includes>
    </dependencySet>
  </dependencySets>
</assembly>
<project>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>msa</groupId>
    <artifactId>root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>
  <artifactId>db-delivery</artifactId>
  <packaging>pom</packaging>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
</project>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。