【问题标题】:Maven dependencies all in one fileMaven 依赖项都在一个文件中
【发布时间】:2016-04-13 05:48:02
【问题描述】:

在我的工作区中有许多 Maven 项目。 是否可以在一个文件中列出所有依赖项的版本并告诉 Maven 从中读取它们? 所以我会有一个***.properties(我猜是extection)来代替

<properties> .... </properties>

在我的 poms 中。

编辑:目前我有一个 pom 父母和几个孩子 pom。我想将版本保存在外部文件而不是父 pom 中。

【问题讨论】:

  • 您想要项目之间的共享,而不是模块之间的共享,对吧? (因为在第二种情况下,您可以使用group-iddependency ...)

标签: java maven configuration dependencies version


【解决方案1】:

使用命令:

mvn dependency:tree

【讨论】:

    【解决方案2】:

    您可以创建列出您的依赖版本的父 maven 项目。

    然后在每个项目的 pom.xml 中,您将引用一个 &lt;parent&gt;...&lt;/parent&gt;,它允许继承所有属性,然后使用这些属性。

    父母可能是:

    <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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.sample</groupId>
        <artifactId>SampleParent01</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <packaging>pom</packaging>
    
        <properties>
            <spring.version>4.2.3</spring.version>
        </properties>
    </project>
    

    你的项目会这样引用它:

    <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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.sample</groupId>
        <artifactId>SampleParent01</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    
    <groupId>org.sample</groupId>
    <artifactId>SampleProject01</artifactId>
    <version>1.0-SNAPSHOT</version>
    
    <packaging>jar</packaging>
    
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
    </dependencies>
    </project>
    

    【讨论】:

    • 是的,我现在就是这样。 Mabye 我没有充分解释我所拥有的。我想要一个与父 pom 分开的文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多