Maven继承依赖模块的依赖 [英] Maven inherit dependencies of dependency module

查看:80
本文介绍了Maven继承依赖模块的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前我有一个项目,其中模块B依赖于模块A.

Currently I have a project where module B depends on module A.

模块A为:

  <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.A</groupId>
    <artifactId>P</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>A</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <name>A</name>
  <build>
    <sourceDirectory>${sourceDirectory}/A/src</sourceDirectory>
  </build>
  <dependencies>
    <dependency>
      <groupId>org.osgi</groupId>
      <artifactId>org.osgi.core</artifactId>
      <version>5.0.0</version>
      <optional>true</optional>
    </dependency>
  </dependencies>
</project>

模块B为:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.A</groupId>
    <artifactId>P</artifactId>
    <version>1.0.0</version>
  </parent>
  <artifactId>B</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <name>B</name>
  <build>
    <sourceDirectory>${sourceDirectory}/B/src</sourceDirectory>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.A</groupId>
      <artifactId>C</artifactId>
      <version>1.0.0</version>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.A</groupId>
      <artifactId>A</artifactId>
      <version>1.0.0</version>
    </dependency>
  </dependencies>
</project>

为了编译B,我需要a-dep中的类.如果我手动将a-dep作为依赖项添加,则一切都可以正常编译.但是该项目需要我依靠A来获取a-dep,而不是显式声明a-dep.

In order to compile B I need the classes in a-dep. If I manually add a-dep as a dependency everything compiles fine. But the project needs me to depend on A to get to a-dep instead of explicitly declare a-dep.

是否有一种方法可以根据模块A从a-dep获取类?

Is there a way to get the classes from a-dep by depending on module A?

推荐答案

能够通过删除true标签来解决此问题,因为它阻止了B能够看到依赖关系.

was able to solve it by removing the true tag as it prevents B to be able to see the dependency.

这篇关于Maven继承依赖模块的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆