在Maven中指定非编译依赖项并将它们打包为资源

Thi*_*ilo 5 java build-automation maven-2

我需要构建一个包含(其他外部项目)Maven工件的jar文件.

人工制品将被包含在内src/main/resources,不需要任何处理.即使它们本身恰好是jar文件,它们也不是我的代码的编译时依赖性,并且不应该在编译,测试或运行时阶段添加到类路径中.

我可以通过下载文件并将它们放入来完成此操作src/main/resources,但我宁愿使用Maven存储库解决它们.

Cug*_*uga 2

以下是您可以添加到 pom 的示例 - 它将使用指定 ID 的工件从指定项目复制到您指定的位置。

<plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy</id>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>id.of.the.project.group.to.include</groupId>
                  <artifactId>id-of-the-project's-artifact-to-include</artifactId>
                  <version>${pom.version}</version>
                </artifactItem>
              </artifactItems>
              <includeArtifactIds>id-of-the-project's-artifact-to-include</includeArtifactIds>
              <outputDirectory>${project.build.directory}/etc-whatever-you-want-to-store-the-dependencies</outputDirectory>
            </configuration>
          </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)