开发者

how to include 2nd level dependencies using maven

开发者 https://www.devze.com 2023-01-18 19:54 出处:网络
I have project A which a pom.xml dependency of: <dependency> <groupId>org.apache.commons</groupId>

I have project A which a pom.xml dependency of:

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-email</artifactId>
        <version>1.2</version>
    </dependency>

commons-email depends on javax.mail-1.4.1

I ran mvn install to install projectA.jar into the local maven repo.

In project B, i depend projectA.jar. When I run project B, it fails due to a missing class file in javax:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
java.lang.ClassNotFoundException: com.sun.mail.smtp.SMTPTransport

How can i run project B successfully without explicitly putting a maven entry for the javax.mail jar?


EDIT:

I think I found the problem. I was using maven-shade-plugin with true and it was removing the org.apache.commons:commons-email:jar dependencies开发者_如何学编程 in installed(.m2) project A pom file.

Commenting out the maven-shade-plugin for project A fixed the dependency problem.


How can i run project B successfully without explicitly putting a maven entry for the javax.mail jar?

Well, that's weird. c.s.m.s.SMTPTransport is supposed to be provided by mail-1.4.1.jar which is a dependency of commons-email. Project B should get it transitively.

Could you run the following on project B and post the output

mvn dependency:tree

Update: There is definitely something weird with your dependencies and I can't reproduce the problem.

I quickly created a first project with the following pom:

<project>
  ...
  <groupId>com.stackoverflow</groupId>
  <artifactId>Q3875317-A</artifactId>
  <dependencies>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-email</artifactId>
      <version>1.2</version>
    </dependency>
  </dependencies>
</project>

And another one depending on the first artifact:

<project>
  ...
  <groupId>com.stackoverflow</groupId>
  <artifactId>Q3875317-B</artifactId>
  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>Q3875317-A</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>
</project>

And here is the dependency tree I get for the second project:

$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3875317-B
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] com.stackoverflow:Q3875317-B:jar:1.0-SNAPSHOT
[INFO] +- com.stackoverflow:Q3875317-A:jar:1.0-SNAPSHOT:compile
[INFO] |  \- org.apache.commons:commons-email:jar:1.2:compile
[INFO] |     +- javax.mail:mail:jar:1.4.1:compile
[INFO] |     \- javax.activation:activation:jar:1.1:compile
[INFO] \- junit:junit:jar:3.8.1:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
...

Everything is there, as expected.

If you get a different result and if there is anything noticeable about your POMs, please show them.

PS: I removed one of the command I initially suggested as it didn't allow to see transitive dependencies.

0

精彩评论

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