Build helper Maven Plugin property not working for resource targetPath

1.3k Views Asked by At

I'm using the Build Helper Maven Plugin to construct a property that is the version with "-" for "."... I have it configured as follows:

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>build-helper-maven-plugin</artifactId>
   <version>1.10</version>
   <executions>
      <execution>
         <id>regex-property</id>
         <goals>
            <goal>regex-property</goal>
         </goals>
         <configuration>
            <name>webscript.version</name>
            <value>${project.version}</value>
            <regex>\.</regex>
            <replacement>-</replacement>
            <failIfNoMatch>false</failIfNoMatch>
         </configuration>
    </execution>
  </executions>
</plugin>

This works fine when I'm building resources that contain the ${webscript.version} property (they are correctly substituted as expected within the file), so this is working:

<resource>
    <targetPath>./alfresco/site-webscripts/org/alfresco/aikau/${project.version}/webscripts</targetPath>
    <filtering>true</filtering>
    <directory>${basedir}/src/main/resources/webscripts</directory>
</resource>

However, the problem I'm having is in using the property anywhere else within the project... what I want to do is to use the property for a target folder, like this:

<resource>
   <targetPath>./alfresco/site-webscripts/customizations/${webscript.version}</targetPath>
   <filtering>true</filtering>
   <directory>${basedir}/src/main/resources/extension-webscripts</directory>
</resource>

With this code, the folder created is simply "${webscript.version}" and not "1-0-66" (in the case where the current version is 1.0.66).

Both the working and not-working examples are in the same <build> element and so I'm assuming are in the same phase.

Can someone advise me on how I can adjust the configuration to get this to work, or to suggest an alternative approach to replacing "." with "-" as a new property that will work in this case?

2

There are 2 best solutions below

0
On

I was able to work around this using the maven-antrun-plugin with the following execution:

<execution>
  <id>rename-extensions-folder</id>
  <phase>prepare-package</phase>
  <goals>
     <goal>run</goal>
  </goals>
  <configuration>
     <target>
        <echo>Renaming folder</echo>
        <move file="${project.build.outputDirectory}/alfresco/site-webscripts/customizations/${project.version}"
              tofile="${project.build.outputDirectory}/alfresco/site-webscripts/customizations/${webscript.version}"/>
      </target>
  </configuration>
</execution>

...although I'd still really like to know how to make use of the custom property without needing this step!

0
On

you may use gmaven-plugin is groovy maven plugin is really powerful

<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.4</version>
<executions>
  <execution>
    <id>change-properties</id>
    <phase>initialize</phase>
    <goals>
      <goal>execute</goal>
    </goals>
    <configuration>
      <source>
        if (something) {
            project.properties.myProperty = 'myPropertyValue'
        }
      </source>
    </configuration>
  </execution>
</executions>

here another Example

hope this helps