【问题标题】:How to add different dependencies on different module in different profile?如何在不同的配置文件中为不同的模块添加不同的依赖项?
【发布时间】:2017-06-13 08:52:51
【问题描述】:

我有一个多模块项目,它通过 maven 管理依赖项。

我在子模块“插件”中有多个插件。我想在不同的场景中添加不同的插件,但是每个场景都需要一些插件。

“插件”模块中的 pom.xml。

<profiles>
   <profile>
        <id>internal</id>
        <modules>
            <module>first-plugin</module>
        </modules>
        <dependencies>
            <dependency>
                <groupId>com.first.groups</groupId>
                <artifactId>first-plugin</artifactId>
                <version>${project.version}</version>
            <dependency>
        </dependencies>
   </profile>
</profiles>
<modules>
    <module>second_module</module>
</modules>
<dependencies>
    <dependency>
        <groupId>com.first.groups</groupId>
        <artifactId>second-module</artifactId>
        <version>${project.version}</version>
    <dependency>
</dependencies>

无论我运行“mvn package”还是“mvn package -P internal”,它都只包含第二个模块作为依赖项。谁知道原因?

我的maven版本是3.3.9

【问题讨论】:

    标签: maven


    【解决方案1】:

    所以,如果你问这个想法的方法,它会是这样的:

    1. 创建一个负责构建所有项目的父项目 例如
             <modules>
                <module>first _module</module>
                <module>second_module</module>
              </modules>
    
    1. 使用依赖管理来管理依赖

      <dependencyManagement/> tag  
      
    2. 如果所有模块中都存在公共依赖项,则将该依赖项放在父项中,并将该项目作为所有模块中带有标记的父项目。所以,所有的项目都会得到共同的依赖

    3. 仅在特定项目中放置特定依赖项
    4. 注意循环依赖。非常小心地创建和提供依赖项。

    【讨论】:

    • 我认为这不是一个好主意。它会破坏我的项目结构。我还是想用maven profile来解决这个问题。
    猜你喜欢
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 2020-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多