我有几个具有几乎相同属性的mvn项目。什么是外部化这些属性的最佳方法,所以我没有重复它们。
首先是属性:
<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>
答案 0 :(得分:2)
您可以使用所有子项目使用的父项目。将公共属性移动到父maven项目中,然后将这样的内容添加到子项目中:
<parent>
<groupId>com.parent</groupId>
<artifactId>parent-project</artifactId>
<version>1</version>
<relativePath/>
</parent>