Maven中的变量替换

时间:2016-01-27 15:27:24

标签: xml maven apigee

我是maven的新手,我尝试使用变量根据命令行中提供的条目更改字段的内容。

我在目录apiproxy中有以下名为weatherxml.xml的xml文件:

<APIProxy name="weatherxml">?
    <ConfigurationVersion majorVersion="4" minorVersion="0"/>
    <CreatedAt>1453818052</CreatedAt>
    <Description>${description}</Description>
    <DisplayName>weatherxml</DisplayName>
    <validate>true</validate>
</APIProxy>

在pom.xml文件中我有这段代码:

<resources>
  <resource>
    <directory>apiproxy</directory>
    <filtering>true</filtering>
  </resource>
</resources>       

这是用于构建

的测试配置文件
<profile>
  <id>test</id>
  <properties>
    <apigee.profile>test</apigee.profile>
    <apigee.env>${api_environment}</apigee.env>
    <apigee.hosturl>${api_hosturl}</apigee.hosturl>
    <apigee.apiversion>v1</apigee.apiversion> <!-- value of version in  https://api.enterprise.apigee.com/v2 -->
    <apigee.org>${api_organization}</apigee.org>
    <apigee.username>${username}</apigee.username>
    <apigee.password>${password}</apigee.password>
    <apigee.options>override</apigee.options>
    <apickli.env>.test</apickli.env>
  </properties>
</profile>

如果我使用

调用maven
mvn resources:resources -Ddescription="Test description" 

它创建了目标目录,我可以看到已经进行了更改。但是,如果我调用

mvn install -Ptest -Dusername=xxx -Dpassword=yyy -Dhost=www.aaa.com -Ddescription="Test description" 

它构建和部署代码,但描述字段包含&#34; $ {description}&#34;文本而不是&#34;测试说明&#34;。

如何在部署的代码中获取变量替换?我不知道这是否与插件的使用有关,可能其中一些会覆盖它。

<build>

    <resources>
      <resource>
        <directory>apiproxy</directory>
        <filtering>true</filtering>
      </resource>
    </resources>

    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>io.apigee.build-tools.enterprise4g</groupId>
                <artifactId>apigee-edge-maven-plugin</artifactId>
                <version>1.0.0</version>
            </plugin>
        </plugins>
    </pluginManagement> 

        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>

                 <!--Copy the full apiproxy folder to target folder -->
                <execution>
                    <id>copy-apiproxy-resources</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                         <!--this is important -->
                        <overwrite>true</overwrite>
                         <!--target -->
                        <outputDirectory>${target.root.dir}/apiproxy</outputDirectory>
                        <resources>
                            <resource>
                                 <!--source -->
                                <directory>${project.root.dir}/apiproxy</directory>
                            </resource>
                        </resources>                            
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>io.apigee.build-tools.enterprise4g</groupId>
            <artifactId>apigee-edge-maven-plugin</artifactId>
            <configuration>
                 <!--Use this module level config to skip module build. Make it true -->
                <skip>false</skip> 
            </configuration>
            <executions>
                <execution>
                    <id>configure-bundle-step</id>
                    <phase>package</phase>
                    <goals>
                        <goal>configure</goal>
                    </goals>
                </execution>
                 <!--deploy bundle -->
                <execution>
                    <id>deploy-bundle-step</id>
                    <phase>install</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <!-- cleaning dirs -->
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>

            <executions>
                <execution>
                    <id>auto-clean-init</id>
                    <phase>initialize</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>auto-clean-install</id>
                    <phase>install</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- run cucumber / apickli tests -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.2</version>
            <executions>
                <!-- run integration tests -->
                <execution>
                    <id>integration</id>
                    <phase>install</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <environmentVariables>
                            <NODE_ENV>
                                ${apigee.env}
                            </NODE_ENV>
                        </environmentVariables>
                        <executable>cucumber-js</executable>
                        <commandlineArgs>
                            tests/integration${apickli.env} --format json:cucumber-result.json
                        </commandlineArgs>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>

0 个答案:

没有答案