You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何无需脚本或Gradle任务在test.bndrun的-runproperties中设随机值

问题:在Bndtools项目中通过Gradle运行测试时,无需修改文件为runproperties设置随机值?

我通过Gradle运行Bndtools项目的bnd测试时,希望在test.bndrun文件的-runproperties中设置随机值,格式如下:

-runproperties: \
    osgi.instance.area=random_value

其中random_value为随机内容(例如"area_" + <currentTimeMillis>)。请问是否无需脚本或Gradle任务修改文件就能实现该需求?


回答

可以实现,无需修改test.bndrun文件,直接利用Bnd本身的属性表达式支持即可:

  • 若要生成基于当前时间戳的随机值,直接在-runproperties中使用Bnd内置的${time}属性,它会自动替换为毫秒级时间戳,写法如下:

    -runproperties: \
        osgi.instance.area=area_${time}
    

    这和你需求的"area_" + <currentTimeMillis>效果完全一致。

  • 如果需要更纯粹的随机数值,可使用Bnd内置的${random}属性,它会生成随机长整型数值,示例:

    -runproperties: \
        osgi.instance.area=area_${random}
    

这些表达式会在Bnd处理bndrun文件的阶段自动解析替换,全程不需要额外脚本或Gradle任务修改文件内容。


内容的提问来源于stack exchange,提问作者Jmini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 01:49:53