Wenn Werte sich in der Datei pom.xml eines Maven-Projekts oft wiederholen, dann ist das ein gutes Indiz, um diese Werte als Eigenschaft (engl. property) zu deklarieren. Folgende zwei Beispiele verdeutlichen die Reduzierung der Wartungsarbeit bei Verwendung einer Property.
Ohne Properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| <project ...>
...
<dependencies>
<!-- http://repo.maven.apache.org/maven2/taglibs/standard/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<scope>runtime</scope>
<version>1.1.2</version>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/c/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>c</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/fmt/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>fmt</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
</dependencies>
...
</project> |
<project ...>
...
<dependencies>
<!-- http://repo.maven.apache.org/maven2/taglibs/standard/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<scope>runtime</scope>
<version>1.1.2</version>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/c/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>c</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/fmt/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>fmt</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
</dependencies>
...
</project>
Mit Properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| <project ...>
...
<properties>
<taglibs.version>1.1.2</taglibs.version>
</properties>
...
<dependencies>
<!-- http://repo.maven.apache.org/maven2/taglibs/standard/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<scope>runtime</scope>
<version>${taglibs.version}</version>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/c/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>c</artifactId>
<version>${taglibs.version}</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/fmt/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>fmt</artifactId>
<version>${taglibs.version}</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
</dependencies>
...
</project> |
<project ...>
...
<properties>
<taglibs.version>1.1.2</taglibs.version>
</properties>
...
<dependencies>
<!-- http://repo.maven.apache.org/maven2/taglibs/standard/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<scope>runtime</scope>
<version>${taglibs.version}</version>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/c/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>c</artifactId>
<version>${taglibs.version}</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
<!-- http://repo.maven.apache.org/maven2/taglibs/fmt/ -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>fmt</artifactId>
<version>${taglibs.version}</version>
<scope>runtime</scope>
<type>tld</type>
</dependency>
</dependencies>
...
</project>