-P标志用于gradle属性,-D标志用于JVM属性。因为测试可能是在新的JVM中派生的,所以传递给gradle的-D参数不会传播到测试中-听起来这就是您所看到的行为。
您可以
test像完成操作一样在您的块中使用systemProperty,但可以通过将其与-P一起传递来基于传入的gradle属性:
test { systemProperty "cassandra.ip", project.getProperty("cassandra.ip")}或者,如果您通过-D传递
test { systemProperty "cassandra.ip", System.getProperty("cassandra.ip")}


