Gradle テスト タスクのシステム プロパティを動的に構成することは可能ですか? 私はそれを機能させる方法を見つけていません。
私は自分のGradleプラグイン内で作業していますGwtPlugin
. メソッドは次のapply()
ようになります。
/** Apply the plugin. */
void apply(Project project) {
project.plugins.apply(JavaPlugin)
project.plugins.apply(WarPlugin)
project.extensions.create("gwt", GwtPluginExtension, project)
project.extensions.create("testSuite", TestSuitePluginExtension, project)
project.convention.plugins.gwt = new GwtPluginConvention(project)
applyGwt(project)
applyTestSuite(project)
}
このapplyTestSuite()
メソッドでは、テスト スイートのタスクを作成します。タスクの定義はintegrationtest
次のようになります。
// Run integration tests, assumed to be found in a class suites/IntegrationTestSuite.
project.task("integrationtest", type: org.gradle.api.tasks.testing.Test, dependsOn: project.tasks.buildApplication) {
workingDir = { project.testSuite.getWorkingDir() == null ? project.projectDir : project.testSuite.getWorkingDir() }
scanForTestClasses = false
scanForTestClasses = false
enableAssertions = false
outputs.upToDateWhen { false }
include "suites/IntegrationTestSuite.class"
systemProperty "integration.test.server.wait", project.gwt.getServerWait()
beforeSuite { descriptor ->
if (descriptor.className == "suites.IntegrationTestSuite") {
project.convention.plugins.gwt.rebootDevmode()
}
}
afterSuite { descriptor ->
if (descriptor.className == "suites.IntegrationTestSuite") {
project.convention.plugins.gwt.killDevmode()
}
}
}
integration.test.server.wait
からシステム プロパティの構成を取得したいと考えていますproject.gwt.getServerWait()
。これを機能させる方法がわかりません。不可能だと思い始めています。
システム プロパティをハードコーディングすると、すべてが期待どおりに機能します。
systemProperty "integration.test.server.wait", 10
問題は、タスクの定義時にシステム プロパティが設定されているようですが、その時点で拡張機能に値がありません。これを回避する方法がわかりません。
たとえば、project.gwt.getServerWait()
呼び出しをクロージャーに入れようとしましたが、その場合、システム プロパティは次のような文字列に設定されます。
com.me.gradle.GwtPlugin$_applyTestSuite_closure10_closure42@320de756
systemProperty
また、行をdoFirst
ブロックに移動してみました。その場合、doFirst
ブロックは私の拡張機能から適切な値を取得します (出力できます) が、割り当てが遅すぎてテスト ランナーに影響を与えないようです。
これを達成する方法はありますか?そうでない場合、動的構成をテスト ランナーに渡す別の方法はありますか?