brain storm
brain storm

Reputation: 31252

maven replacer plugin in not working

Here is the relevant part of pom.xml

 <plugin>
           <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
             <version>1.5.2</version>
            <executions>
              <execution>
             <phase>pre-package</phase>
                 <goals>
                    <goal>replace</goal>
                  </goals>
                 </execution>
                </executions>
                    <configuration>
                       <file>target/swagger/api.json</file>
                <regex>false</regex>
                <token>$BUILD_NUMBER$</token>
                <value>${project.version}</value>
                        </configuration>
 </plugin>

Here is api.json file

{
    "apiVersion": "$BUILD_NUMBER$"
    "developers": ["foo", "bar"]
} 

After I run, mvn clean package, I do not see target/swagger/api.json being updated with project.version

Upvotes: 2

Views: 3677

Answers (2)

olidoodle
olidoodle

Reputation: 129

Make sure your plugin declaration is in <build><plugins>

And not in <build><pluginManagement><plugins>

Also, in case your project is part of a bigger maven project, it's safer to use ${project.build.directory} instead of target :

<file>target/swagger/api.json</file>

Upvotes: 1

swisscoder
swisscoder

Reputation: 129

  1. think about the maven build phase upon you want to replace it, select a phase before u generate the docs with swagger f.ex. "validate" and set the swagger docs generation to "compile"
    1. exchange the $BUILD_NUMBER$ into %BUILD_NUMBER%
    2. Think about that this way you need to manually reset the value again to the %BUILD_NUMBER%

Upvotes: 0

Related Questions