From 785fce577964a2f4acc87647f5d87ed5258b0575 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 26 Apr 2023 11:29:08 +0100 Subject: [PATCH 1/2] Run export tasks sequentially for more predictability Without the tasks run in sequence, the following error is reported by Gradle >= 7.0: ``` Task ':structurizrCliExport-plantuml0' uses this output of task ':structurizrCliExport-plantuml1' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed ``` --- .../structurizrcli/ExportFunctionalTest.kt | 36 +++++++++++++++++++ .../structurizrcli/StructurizrCliPlugin.kt | 9 +++-- .../gradle/structurizrcli/tasks/Export.kt | 2 +- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/ExportFunctionalTest.kt b/src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/ExportFunctionalTest.kt index 5a53a92..9f9e42e 100644 --- a/src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/ExportFunctionalTest.kt +++ b/src/functionalTest/kotlin/pl/zalas/gradle/structurizrcli/ExportFunctionalTest.kt @@ -41,4 +41,40 @@ class ExportFunctionalTest : FunctionalTest { assertTrue(File("${projectDir.absolutePath}/structurizr-SystemContext.puml").exists()) } + + @Test + fun `it exports multiple workspaces`(@TempDir projectDir: File, @TempDir workspaceDir1: File, @TempDir workspaceDir2: File) { + givenWorkspace(workspaceDir1, "workspace1.dsl") + givenWorkspace(workspaceDir2, "workspace2.dsl") + givenConfiguration(projectDir, """ + plugins { + id 'pl.zalas.structurizr-cli' + } + structurizrCli { + export { + format = "plantuml" + workspace = "${workspaceDir1.absolutePath}/workspace1.dsl" + } + export { + format = "plantuml" + workspace = "${workspaceDir2.absolutePath}/workspace2.dsl" + } + export { + format = "json" + workspace = "${workspaceDir1.absolutePath}/workspace1.dsl" + } + export { + format = "json" + workspace = "${workspaceDir2.absolutePath}/workspace2.dsl" + } + } + """) + + execute(projectDir, "structurizrCliExport") + + assertTrue(File("${workspaceDir1.absolutePath}/structurizr-SystemContext.puml").exists()) + assertTrue(File("${workspaceDir2.absolutePath}/structurizr-SystemContext.puml").exists()) + assertTrue(File("${workspaceDir1.absolutePath}/workspace1.json").exists()) + assertTrue(File("${workspaceDir2.absolutePath}/workspace2.json").exists()) + } } diff --git a/src/main/kotlin/pl/zalas/gradle/structurizrcli/StructurizrCliPlugin.kt b/src/main/kotlin/pl/zalas/gradle/structurizrcli/StructurizrCliPlugin.kt index fb6bb90..a4b022b 100644 --- a/src/main/kotlin/pl/zalas/gradle/structurizrcli/StructurizrCliPlugin.kt +++ b/src/main/kotlin/pl/zalas/gradle/structurizrcli/StructurizrCliPlugin.kt @@ -65,12 +65,15 @@ class StructurizrCliPlugin : Plugin { // export tasks need to be created once configuration has been processed extension.exports.forEachIndexed { index, export -> export.name = export.name.ifEmpty { export.format.replace("/", "-") + index } - tasks.register("structurizrCliExport-${export.name}", Export::class.java) { task -> + tasks.register(export.taskName(), Export::class.java) { task -> task.dependsOn("structurizrCliExtract") task.workspace.set(layout.projectDirectory.file(export.workspace)) task.format.set(export.format) task.structurizrCliJar.set(extract.flatMap { it.structurizrCliJar }) - task.structurizrCliDirectory.set(layout.buildDirectory.dir("structurizr-cli")) + task.structurizrCliDirectory.set(structurizrDirectory(extension)) + extension.exports.getOrNull(index-1)?.also { precedingExport -> + task.mustRunAfter(precedingExport.taskName()) + } } } } @@ -97,4 +100,6 @@ class StructurizrCliPlugin : Plugin { extension.extract.directory?.let { layout.projectDirectory.dir(it) } ?: layout.buildDirectory.dir("structurizr-cli").get() + + private fun StructurizrCliPluginExtension.Export.taskName() = "structurizrCliExport-${this.name}" } diff --git a/src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Export.kt b/src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Export.kt index b74e3c7..f27c8aa 100644 --- a/src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Export.kt +++ b/src/main/kotlin/pl/zalas/gradle/structurizrcli/tasks/Export.kt @@ -47,7 +47,7 @@ open class Export : DefaultTask() { fun export() { project.javaexec { spec -> spec.workingDir(project.layout.projectDirectory) - spec.classpath(structurizrCliJar.get(), structurizrCliDirectory.dir("lib/*")) + spec.classpath(structurizrCliDirectory.dir("lib/*")) spec.mainClass.set("com.structurizr.cli.StructurizrCliApplication") spec.args("export", "-workspace", workspace.get(), "-format", format.get()) } From 72afe6940b8157a55ce1fdf65cace0eb3cb900ed Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Wed, 26 Apr 2023 11:36:34 +0100 Subject: [PATCH 2/2] Update Gradle *8.0.1 -> 8.1.1) --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fc10b60..37aef8d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists