Maven2:设置为编译的依赖项未添加到战争中

发布于 2024-09-30 12:08:33 字数 1485 浏览 1 评论 0原文

我有一个多模块项目,由几个 jar 模块和一个 war 模块组成。当我执行 mvn package 时,会创建 war,但 war 的 lib 文件夹中不包含一个依赖项(javax.mail)。 依赖设置为compile的是主pom。 war 并不依赖于 mail.jar,而是依赖于 module.jar。 当我执行 mvn dependency:tree 时,这三个对我来说看起来不错。在调试中运行也没有显示出任何错误。

有人有主意吗?

BB Peter

Edit:在主 POM 中,我将其

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.1</version>
    <scope>compile</scope>
</dependency>

作为托管依赖项。模块 jar 具有如下依赖关系:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
</dependency>

war 模块对 javax.mail 没有依赖关系。

Edit2:

我确实重写了 master pom 中的 war 插件,如下所示:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warName>${war.name}</warName>
        <archive>
            <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
            <manifestEntries>
                <Implementation-Build>${buildNumber}</Implementation-Build>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

I have a multi module project consisting of several jar modules and a war module. When I do mvn package, the war is created but one dependency (javax.mail) is not included in the lib folder of the war.
The dependency is set to compile is the main pom. The war is not dependent from the mail.jar but a module.jar is.
When I do mvn dependency:tree, the three looks fine to me. Running in debug does not show me anything wrong either.

Anyone has an idea?

BB
Peter

Edit: in the master POM I have

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.1</version>
    <scope>compile</scope>
</dependency>

as a managed dependency. The module jar has the dependency as follows:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
</dependency>

The war module has no dependency to javax.mail.

Edit2:

I do override the war plugin in the master pom like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warName>${war.name}</warName>
        <archive>
            <manifest>
            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
            <manifestEntries>
                <Implementation-Build>${buildNumber}</Implementation-Build>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

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

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

发布评论

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

评论(2

余生再见 2024-10-07 12:08:33

你的 pom 或 master pom 是否覆盖了 maven-war-plugin?可以明确地将工件排除在战争中:

http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#packagingExcludes

另外,
http://maven.apache.org/plugins/maven -war-plugin/war-mojo.html#warSourceExcludes

...我记不清这两个排除之间的区别,而且如果您不覆盖 war 插件也没关系。

Does your pom or master pom override the maven-war-plugin? It's possible to explicitly exclude artifacts from being put in the war:

http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#packagingExcludes

Also,
http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#warSourceExcludes

...I can't remember exactly the difference between the two excludes, and it doesn't really matter if you're not overriding the war plugin anyway.

ゝ杯具 2024-10-07 12:08:33

如果 javax.mail 依赖项是您的模块之一的依赖项,则应包含它。但是,如果将其定义为可选依赖项,则会破坏传递依赖机制。

换句话说,如果在您的模块中,您有这样的定义:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.1</version>
    <optional>true</optional>
</dependency>

如果是这种情况,只需删除此 true 语句即可。

If the javax.mail dependency is a dependency of one of your module, it should be included. However, if it is defined as an optional dependency, it will break the transitive dependency mechanism.

In others words, if in your module, you have that definition:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.1</version>
    <optional>true</optional>
</dependency>

If this is the case, simply remove this <optional>true</optional> statement.

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