我正在使用 maven-android-plugin 并且我正在使用一种偷偷摸摸的令牌替换机制来做到这一点。
我正在使用“morseflash”示例,并将其添加到 maven-resources 插件配置中:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
</executions>
<configuration>
<delimiters>
<delimiter>${*}</delimiter>
<delimiter>>08*<</delimiter>
</delimiters>
</configuration>
</plugin>
资源插件允许您为搜索/替换定义奇怪的分隔符。默认分隔符是${*}
,但我添加>*<
了它以匹配 XML 元素内容。(实际上我用过>08*<
;我稍后会解释原因。)
然后,在我的 strings.xml 中,我写了这个:
<string name="googleMapsAPIKey">08DEBUGKEYABCDEFBLAHBLAHBLAH</string>
并在发布配置文件中定义了一个 Maven 属性,如下所示:
<profile>
<id>release</id>
<!-- via this activation the profile is automatically used when the release is done with the maven release
plugin -->
<activation>
<property>
<name>performRelease</name>
<value>true</value>
</property>
</activation>
<properties>
<DEBUGKEYABCDEFBLAHBLAHBLAH>>08RELEASEKEYABCDEFBLAHBLAHBLAH<</DEBUGKEYABCDEFBLAHBLAHBLAH>
</properties>
<-- ... -->
</profile>
这会创建一个以调试 Maps 键命名的 Maven 属性,其值是发布调试键。
不幸的是,Maven 属性不允许以数字开头。我的调试密钥和我的发布密钥都以08Wfj...
所以我使用了分隔符>08*<
并确保包含>08
在我的替换字符串中。