Luc Dewavrin's weblog

Ant's Replaceregexp Task in a Maven Pom File

| Comments

Since it can be tricky, here’s how Ant’s regexp task can be used in a maven pom file:

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
40
41
42
<plugin>
  <artifactId>maven-antrun-plugin</artifactId>
  <executions>
    <execution>
      <phase>compile</phase>
      <configuration>
        <tasks>
          <echo>Online uncomment of ${basedir}/src/main/resources/beanRefContext.xml</echo>
          <copy>
              file="${basedir}/src/main/resources/beanRefContext.xml"
              todir="${basedir}/target/classes" /&gt;
          <replaceregexp>
              file="${basedir}/target/classes/beanRefContext.xml"
              match="&lt;!--s*(&lt;[^-{2}]+)--&gt;" replace="1"
              byline="true" /&gt;
        </replaceregexp>
          </copy>
        </tasks>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
  <dependencies>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-nodeps</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-regexp</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <artifactId>jakarta-regexp</artifactId>
      <groupId>jakarta-regexp</groupId>
      <version>1.4</version>
    </dependency>
  </dependencies>
</plugin>

Comments