开发者

Maven2: dependency set to compile not added to war

开发者 https://www.devze.com 2023-01-23 07:16 出处:网络
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

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>
    <artifact开发者_JAVA技巧Id>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>


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消