在正常开发过程中,我需要执行某个构建函数。在发布期间,构建函数需要替换为发布等效项(在本例中为 Proguarding 而不是复制)。

我认为我可以使用 2 个配置文件(一个 DevelopmentProfile 和一个 ReleaseProfile)以及 DevelopmentProfile activeByDefault 来达到目的。

例如

<profiles> 
    <profile> 
        <id>DevelopmentProfile</id> 
        <activation> 
            <activeByDefault>true</activeByDefault> 
        </activation> 
        <properties> 
            <developmentBuild>true</developmentBuild> 
            <releaseBuild>false</releaseBuild> 
        </properties> 
    </profile> 
    <profile> 
        <id>ReleaseProfile</id> 
        <properties> 
            <developmentBuild>false</developmentBuild> 
            <releaseBuild>true</releaseBuild> 
        </properties> 
    </profile> 
</profiles> 

并通过 release-plugin releaseProfiles 属性打开 ReleaseProfile,并通过 releaseProfiles 属性关闭 ReleaseProfile

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-release-plugin</artifactId> 
    <configuration> 
        <releaseProfiles>ReleaseProfile,!DevelopmentProfile</releaseProfiles> 
    </configuration> 
</plugin> 

考虑到这篇关于“停用配置文件”的文章,这看起来是可行的 http://maven.apache.org/guides/introduction/introduction-to-profiles.html事实上,发布插件的源代码只是使用提供的字符串构建配置文件。

但是好像不行。我怀疑是因为发布插件预先设置了事件配置文件,这可能会覆盖配置文件停用。

无论如何。有没有其他方法可以在发布期间停用配置文件。或者以其他方式确保这两个配置文件中只有一个在任何时候处于事件状态。

而且我对涉及我传递系统属性以显式激活配置文件的解决方案不感兴趣,因为它们不够健壮,无法承受这里的工作量。

请您参考如下方法:

好的,我上面所做的一切都是 100% 正确的。 您完全可以像我上面那样在发布期间停用配置文件。

它对我不起作用的原因是因为显示的 release-plugin 配置已在子 pom 中指定,而父 pom 要么重载了 releaseProfiles 的值,要么完全控制了。

因此将我的配置移至父级使一切正常。


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!