Maven-ear-plugin - 排除多个模块,即 jar、wars 等

发布于 2024-08-25 19:59:34 字数 2156 浏览 5 评论 0原文

我一直在使用 Maven EAR 插件为新项目创建 Ear 文件。我注意到在插件文档中您可以为模块指定排除语句。例如,我的插件的配置如下...

  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
            <jboss>
                <version>5</version>
            </jboss>
            <modules>
                <!-- Include the templatecontroller.jar inside the ear -->
                    <jarModule>
                        <groupId>com.kewill.kdm</groupId>
                        <artifactId>templatecontroller</artifactId>
                        <bundleFileName>templatecontroller.jar</bundleFileName>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </jarModule>
                    <!-- Exclude the following classes from the ear -->
                    <jarModule>
                       <groupId>javax.activation</groupId>
                       <artifactId>activation</artifactId>
                       <excluded>true</excluded>
                    </jarModule>
                    <jarModule>
                   <groupId>antlr</groupId>
                   <artifactId>antlr</artifactId>
                   <excluded>true</excluded>
                </jarModule>
                ... declare multiple excludes
                <security>
                    <security-role id="SecurityRole_1234">
                        <role-name>admin</role-name>
                    </security-role>
                </security>
            </configuration>
        </plugin>
    </plugins>

对于需要排除 4-5 个模块的小型项目来说,这种方法绝对没问题。然而,在我的项目中,我有 30 多个,而且我们才刚刚开始该项目,因此随着项目的扩展,这个数量可能会增加。

除了显式声明每个模块的排除语句之外,是否可以使用通配符或排除所有 Maven 依赖项标志以仅包含我声明的模块并排除其他所有内容?有人知道更优雅的解决方案吗?

I've been using the Maven EAR plugin for creating my ear files for a new project. I noticed in the plugin documentation you can specify exclude statements for modules. For example the configuration for my plugin is as follows...

  <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.4.1</version>
        <configuration>
            <jboss>
                <version>5</version>
            </jboss>
            <modules>
                <!-- Include the templatecontroller.jar inside the ear -->
                    <jarModule>
                        <groupId>com.kewill.kdm</groupId>
                        <artifactId>templatecontroller</artifactId>
                        <bundleFileName>templatecontroller.jar</bundleFileName>
                        <includeInApplicationXml>true</includeInApplicationXml>
                    </jarModule>
                    <!-- Exclude the following classes from the ear -->
                    <jarModule>
                       <groupId>javax.activation</groupId>
                       <artifactId>activation</artifactId>
                       <excluded>true</excluded>
                    </jarModule>
                    <jarModule>
                   <groupId>antlr</groupId>
                   <artifactId>antlr</artifactId>
                   <excluded>true</excluded>
                </jarModule>
                ... declare multiple excludes
                <security>
                    <security-role id="SecurityRole_1234">
                        <role-name>admin</role-name>
                    </security-role>
                </security>
            </configuration>
        </plugin>
    </plugins>

This approach is absolutely fine with small projects where you have say 4-5 modules to exclude. However, in my project I have 30+ and we've only just started the project so as it expands this is likely to grow.

Besides explicitly declaring exclude statements per module is it possible to use wildcards or and exclude all maven dependencies flag to only include those modules i declare and exclude everything else? Is anyone aware of a more elegant solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

橘虞初梦 2024-09-01 19:59:34

除了显式声明每个模块的排除语句之外,是否可以使用通配符或排除所有 Maven 依赖项标志以仅包含我声明的模块并排除其他所有内容?

ma​​ven-ear-plugin 不会不提供开箱即用的此功能(而且我认为配置起来并不容易,耳朵必须非常精确地包装)。但是,这里不清楚的是如何获取需要排除的依赖项。根据您的答案,可能有多种方法来处理它们:

  • 如果它们是您的工件的依赖项,您可以将其中一些声明为可选,以避免传递地检索它们。
  • 您可以将某些依赖项标记为“已提供”(并将它们放入父 pom 中,仅在 EAR 的 POM 中重新声明您想要的内容)。

但在没有看到全貌的情况下很难回答。

Besides explicitly declaring exclude statements per module is it possible to use wildcards or and exclude all maven dependencies flag to only include those modules I declare and exclude everything else?

The maven-ear-plugin doesn't provide this feature out-of-box (and I don't think that it would be easy to configure anyway, an ear must be packaged very precisely). However, what's not clear here is how you get the dependencies you need to exclude. Depending on your answer, there could be several ways to handle them:

  • You could maybe declare some of them as optional if they are dependencies of your artifacts to avoid to retrieve them transitively.
  • You could maybe mark some dependencies as "provided" (and put them in a parent pom, redeclare only what you want in the POM of the EAR).

Hard to answer without seeing the whole picture though.

羁〃客ぐ 2024-09-01 19:59:34

不确定是否支持通配符,但编写自己的 mojo 非常简单。您可以包装现有的 mojo,然后采用您自己设计的一些任意配置,例如通配符语法。

更好的是,您可以将您的魔力提交给 Maven 团队(!)

Not sure about whether wildcards are supported, but it is very simple to write your own mojo. You could wrap the existing mojo and then take some arbitrary config of your own design, such as your wildcard syntax.

Better still, you could submit your mojo to the maven team (!)

流年已逝 2024-09-01 19:59:34

我面临着类似的问题。但那是因为我有一个多模块项目,其中有几个具有所提供范围的罐子,我刚刚从子ear pom中删除了父标签,从而使其独立。然后使用 include 包含我需要的尽可能多的罐子。

希望这有帮助!

i was facing a similar problem. but that was because i had a multi module project with several jars having the provided scope , i just removed the parent tag from the child ear pom , there by making it independent . and then using include to include as many jars i need.

hope this helps!!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文