在 pom.xml 中外部化属性的最佳方法是什么 [英] What is the best way to externalize properties in pom.xml

查看:42
本文介绍了在 pom.xml 中外部化属性的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个具有几乎相同属性的 mvn 项目.将这些属性外部化的最佳方法是什么,这样我就不会复制它们.

I have a few mvn projects with almost the same properties. What is the best way to externalize these properties so i dont have them duplicated.

首先是属性:

<properties>
    <!-- LOMBOK version -->
    <lombok.version>1.16.4</lombok.version>
    <!-- LOGGING versions -->
    <slf4j.version>1.6.4</slf4j.version>
    <log4j.version>1.2.16</log4j.version>
    <!-- MAVEN COMPILER PLUGIN version -->
    <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
    <maven-compiler-plugin.source.version>1.7</maven-compiler-plugin.source.version>
    <maven-compiler-plugin.target.version>1.7</maven-compiler-plugin.target.version>
    <maven-compiler-plugin.compilerVersion>1.7</maven-compiler-plugin.compilerVersion>
</properties>

然后依赖管理:

<dependencyManagement>

    <dependencies>
        <!-- LOMBOK DEPENDENCIES -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
        <!-- LOGGING DEPENDENCIES -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <!-- LOGGING DEPENDENCIES - LOG4J -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>           

</dependencyManagement>

推荐答案

您可以使用所有子项目都使用的父项目.将公共属性移动到父 maven 项目中,然后将类似这样的内容添加到您的子项目中:

You could use a parent project which is used by all your sub-projects. Move the common properties into a parent maven project, and then add something like this to your sub-projects:

<parent>
  <groupId>com.parent</groupId>
  <artifactId>parent-project</artifactId>
  <version>1</version>
  <relativePath/>
</parent>

这篇关于在 pom.xml 中外部化属性的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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