java - Maven组装插件: Fetch files and move them to the right places

标签 java maven maven-assembly-plugin

为了创建一个发行版,我决定使用 Maven 程序集插件。但就我而言,我还需要来自其他项目的资源或仅仅是 Artifact 。让我们在这里使用一个简单的示例,我相信稍后我可以自己解决更复杂的示例。

我们的本地存储库服务器上有一个 zip Artifact ,maven 配置为使用该 Artifact 。该 zip 文件具有平面层次结构,包含 native 代码包装器、jar 文件、自述文件和示例配置。对于分发包,我们需要前两个。包装器应放置在 bin/ 目录中,jar 文件应放置在 lib/ 目录中。但 zip 文件仅在组装步骤中需要。我不需要它来编译或测试。阅读有关依赖范围的文档后,我没有找到适合此特定用例的匹配文档。其他问题在下面的代码中进行了描述: 当我没有将 zip 指定为依赖项时,我以后将无法使用该 Artifact 。而且我无法将解压后的文件放在正确的位置。

也许我的整个方法都是错误的?我很想听听您的意见。

pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.1.0</version>
    <configuration>
        <descriptors>
            <descriptor>src/assembly/dist.xml</descriptor>
        </descriptors>
    </configuration>
    <executions>
        <execution>
            <id>dist</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

dist.xml

 <dependencySets>
    <dependencySet>
        <includes>
            <!-- does only work when specified as a dependency in pom.xml -->
            <include>my:archive</include>
        </includes>
        <outputDirectory>unpacked</outputDirectory>
        <unpack>true</unpack>
        <unpackOptions>
            <includes>
                <include>wrapper</include>
                <include>extraLib.jar</include>
                <!-- can't move or rename -->
            </includes>
        </unpackOptions>
        <useProjectArtifact>false</useProjectArtifact>
    </dependencySet>
  </dependencySets>

最佳答案

我已经通过直接使用 maven-dependency-plugin 而不是 maven-assemble 插件完成了几次类似的事情。

http://maven.apache.org/plugins/maven-dependency-plugin/unpack-mojo.html

这是另一个类似的问题:Unzip dependency in maven

关于java - Maven组装插件: Fetch files and move them to the right places,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60008750/

相关文章:

java - 在 JUnit 5 中使用 Allure 进行测试报告

java - Hibernate Spring JPA javax.persistence.TransactionRequiredException : No transactional EntityManager available

maven - 如何在 Maven 程序集中包含一个空目录?

Maven 程序集插件。有什么方法可以直接从描述 rune 件中解压缩/解压缩存档,而不是依赖 antrun 插件?

Java : loop on all the classes in the classpath

java - 如何让这个程序返回提示直到用户退出

java - eclipse 要求我在 finally block 中用 try/catch 包围 - 可以禁用它吗?

java - 如何检测线程被IO阻塞?

eclipse - 如何解决 Spring Data Maven 构建的 "Plugin execution not covered by lifecycle configuration"

maven - 从 jar (Maven) 中排除依赖项的未使用部分