What is the best way to externalize properties in pom.xml

醉酒当歌 提交于 2021-02-08 17:20:42

问题


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.

First the properties:

<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>

Then dependenciesManagement:

<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>

回答1:


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>


来源:https://stackoverflow.com/questions/32601246/what-is-the-best-way-to-externalize-properties-in-pom-xml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!