@@ -54,14 +54,24 @@ class ClusterFormationTasks {
5454 */
5555 static List<NodeInfo > setup (Project project , String prefix , Task runner , ClusterConfiguration config ) {
5656 File sharedDir = new File (project. buildDir, " cluster/shared" )
57- // first we remove everything in the shared cluster directory to ensure there are no leftovers in repos or anything
58- // in theory this should not be necessary but repositories are only deleted in the cluster-state and not on-disk
59- // such that snapshots survive failures / test runs and there is no simple way today to fix that.
60- Task cleanup = project. tasks. create(name : " ${ prefix} #prepareCluster.cleanShared" , type : Delete , dependsOn : config. dependencies) {
61- delete sharedDir
62- doLast {
63- sharedDir. mkdirs()
64- }
57+ Object startDependencies = config. dependencies
58+ /* First, if we want a clean environment, we remove everything in the
59+ * shared cluster directory to ensure there are no leftovers in repos
60+ * or anything in theory this should not be necessary but repositories
61+ * are only deleted in the cluster-state and not on-disk such that
62+ * snapshots survive failures / test runs and there is no simple way
63+ * today to fix that. */
64+ if (config. cleanShared) {
65+ Task cleanup = project. tasks. create(
66+ name : " ${ prefix} #prepareCluster.cleanShared" ,
67+ type : Delete ,
68+ dependsOn : startDependencies) {
69+ delete sharedDir
70+ doLast {
71+ sharedDir. mkdirs()
72+ }
73+ }
74+ startDependencies = cleanup
6575 }
6676 List<Task > startTasks = []
6777 List<NodeInfo > nodes = []
@@ -103,7 +113,7 @@ class ClusterFormationTasks {
103113 }
104114 NodeInfo node = new NodeInfo (config, i, project, prefix, elasticsearchVersion, sharedDir)
105115 nodes. add(node)
106- Task dependsOn = startTasks. empty ? cleanup : startTasks. get(0 )
116+ Object dependsOn = startTasks. empty ? startDependencies : startTasks. get(0 )
107117 startTasks. add(configureNode(project, prefix, runner, dependsOn, node, config, distro, nodes. get(0 )))
108118 }
109119
0 commit comments