java - 如何让 Maven 多模块程序集将 war 文件与 jar 文件放在单独的子目录中?

标签 java maven maven-2 maven-3 maven-assembly-plugin

使用 maven 3.0.4

我有一个多模块 maven 项目,一些模块生成 war 文件,一些生成 jar 文件,如在各自的 poms 中声明的那样

我想创建一个分发存档,其中 jar Artifact 和依赖项进入一个子目录,webapp Artifact (无依赖项)进入另一个子目录。

有点像

project.tar/lib     <-- module jars and deps here
project.tar/webapp  <-- wars here

让程序集将所有内容转储到一个目录中非常简单。

这是我试过的:

<assembly>
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>

    <moduleSets>
        <moduleSet>
            <includes>
                <include>${module.groupId}:${module.artifactId}:war:${module.version}</include>
            </includes>
            <binaries>
                <includeDependencies>false</includeDependencies>
                <outputDirectory>webapp</outputDirectory>
            </binaries>
        </moduleSet>
        <moduleSet>
            <includes>
                <include>${module.groupId}:${module.artifactId}:jar:${module.version}</include>
            </includes>
            <binaries>
                <includeDependencies>true</includeDependencies>
                <outputDirectory>lib</outputDirectory>
            </binaries>
        </moduleSet>
    </moduleSets>
</assembly>

现在当我运行它时,我收到这些警告:

[INFO] Reading assembly descriptor: assembly.xml
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '${module.groupId}:${module.artifactId}:war:${module.version}'

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '${module.groupId}:${module.artifactId}:jar:${module.version}'

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '${module.groupId}:${module.artifactId}:war:${module.version}'

[WARNING] NOTE: Currently, inclusion of module dependencies may produce unpredictable results if a version conflict occurs.
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '${module.groupId}:${module.artifactId}:jar:${module.version}'

不确定我做错了什么。我的包含遵循 Maven 网页上指定的“group:artifact:version”模式。

谢谢

最佳答案

这似乎可行。不过,不确定这是否是最好的方法。 Maven 似乎不支持 ${module.whatever} 变量。

<dependencySets>
    <dependencySet>
        <includes>
            <include>${project.groupId}:*:war:${project.version}</include>
        </includes>
        <useProjectArtifact>true</useProjectArtifact>
        <outputDirectory>webapp</outputDirectory>
        <unpack>false</unpack>
    </dependencySet>
    <dependencySet>
        <excludes>
            <exclude>${project.groupId}:*:war:${project.version}</exclude>
        </excludes>
        <useProjectArtifact>true</useProjectArtifact>
        <outputDirectory>lib</outputDirectory>
        <unpack>false</unpack>
    </dependencySet>
</dependencySets>

关于java - 如何让 Maven 多模块程序集将 war 文件与 jar 文件放在单独的子目录中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12117916/

相关文章:

java - Spring MVC与Hibernate持久层集成测试

maven-2 - 询问具有默认值的 Maven 原型(prototype)属性

sql - 马文 : Any way to edit resource files?

java - 有没有办法为相同结构表复制 JPARepository 方法?

java - 使用 Java 在 MS Word 文件中创建表格

java - 如何使用 Jar 文件在 IntelliJ IDEA 中设置运行/调试配置?

Java:从 Singleton Holder 模式生成多个内部类

Maven 用于多个模块

java - 更改字符串中的字符(路径)Java

java - 如何使用freebase api获取一个城市的所有旅游景点?我只能从返回的 JSON 中获取 10