2

I am trying to replace string %APP_NAME% with enviroment variable in jdbc.properties using maven. I have following configuration:

<pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.google.code.maven-replacer-plugin</groupId>
                    <artifactId>replacer</artifactId>
                    <version>1.5.2</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>replace</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <basedir>${project.build.directory}/classes</basedir>
                        <includes>
                            <include>jdbc.properties</include>
                        </includes>
                        <replacements>
                            <replacement>
                                <token>%APP_NAME%</token>
                                <value>${env.BRANCH_NAME}</value>
                            </replacement>
                        </replacements>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.6</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                    <executions>
                        <execution>
                            <!-- First step is to disable the default-war build step. -->
                            <id>default-war</id>
                            <phase>none</phase>
                        </execution>
                        <execution>
                            <!-- Second step is to create an exploded war. Done in prepare-package -->
                            <id>war-exploded</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>exploded</goal>
                            </goals>
                        </execution>
                        <execution>
                            <!-- Last step is to make sure that the war is built in the package 
                                phase -->
                            <id>custom-war</id>
                            <phase>package</phase>
                            <goals>
                                <goal>war</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <artifactId>maven-eclipse-plugin</artifactId>
                    <version>2.9</version>
                    <configuration>
                        <additionalProjectnatures>
                            <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                        </additionalProjectnatures>
                        <additionalBuildcommands>
                            <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                        </additionalBuildcommands>
                        <downloadSources>true</downloadSources>
                        <downloadJavadocs>true</downloadJavadocs>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                        <!-- <compilerArgument>-Xlint:all</compilerArgument> -->
                        <showWarnings>true</showWarnings>
                        <showDeprecation>true</showDeprecation>
                        <compilerArguments>
                            <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
                        </compilerArguments>
                    </configuration>
                </plugin>   
        </plugins>
</pluginManagement>

When i invoke:

mvn clean package

or

mvn clean install

the replacer plugin is not called. Can anyone can please explain why and what can I do to let it work? Or if replacer is not compatible with future war plugin can anyone explain me any other way to replace some string in jdbc.properties before building war? I saw also ant plugin but with same config it is not called too.. Example below..

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version> 
    <executions>
        <execution>
            <id>deploy-ui</id>
            <phase>package</phase>
            <inherited>false</inherited> 
            <configuration>
                <tasks>
                    <replace dir="${basedir}/src/main/resources">
                        <include name="**/jdbc.properties" />
                        <replacefilter token="%APP_NAME%" value="${env.BRANCH_NAME}"/>
                    </replace>
                </tasks>
            </configuration>
            <goals>
                <goal>run</goal>
            </goals> 
        </execution>
    </executions>
</plugin>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Gazeciarz
  • 516
  • 1
  • 8
  • 22
  • Possible duplicate of [Maven: what is pluginManagement?](http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement) – A_Di-Matteo Aug 29 '16 at 14:55

1 Answers1

1

The plugin is defined in a <pluginManagement> block:

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>com.google.code.maven-replacer-plugin</groupId>
            <artifactId>replacer</artifactId>
            <version>1.5.2</version>
...

Find the <build><plugins> block for the POM where replacer needs to run, and add the following:

<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
</plugin>

Plugin Management is rather like a template for what should happen when the plugin is invoked. If the plugin is not referenced in the <build><plugins> block, nothing will happen.

user944849
  • 14,524
  • 2
  • 61
  • 83