diff --git a/examples/base-plugin/smithy-build-task/build.gradle.kts b/examples/base-plugin/smithy-build-task/build.gradle.kts index 63e5535..370e273 100644 --- a/examples/base-plugin/smithy-build-task/build.gradle.kts +++ b/examples/base-plugin/smithy-build-task/build.gradle.kts @@ -9,12 +9,17 @@ plugins { id("software.amazon.smithy.gradle.smithy-base").version("1.0.0") } -tasks.create("doit") { +val doIt = tasks.register("doit") { models.set(files("model/")) smithyBuildConfigs.set(files("smithy-build.json")) } -tasks["build"].finalizedBy(tasks["doit"]) +tasks["build"].finalizedBy(doIt) + +tasks.register("copyOutput") { + into(layout.buildDirectory.dir("model")) + from(doIt.map { it.getPluginProjectionDirectory("source", "model") }) +} repositories { mavenLocal() diff --git a/smithy-base/src/it/java/software/amazon/smithy/gradle/SmithyBuildTaskTest.java b/smithy-base/src/it/java/software/amazon/smithy/gradle/SmithyBuildTaskTest.java index 47a41e4..1edc28b 100644 --- a/smithy-base/src/it/java/software/amazon/smithy/gradle/SmithyBuildTaskTest.java +++ b/smithy-base/src/it/java/software/amazon/smithy/gradle/SmithyBuildTaskTest.java @@ -39,4 +39,19 @@ public void testCustomBuild() { "build/smithyprojections/smithy-build-task/source/sources/manifest"); }); } + + @Test + public void pluginProjectionDirectoryExpressesTaskDependency() { + Utils.withCopy("base-plugin/smithy-build-task", buildDir -> { + BuildResult result = GradleRunner.create() + .forwardOutput() + .withProjectDir(buildDir) + .withArguments("copyOutput", "--stacktrace") + .build(); + Utils.assertSmithyBuildDidNotRun(result); + Utils.assertArtifactsCreated( + buildDir, + "build/model/model.json"); + }); + } } diff --git a/smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyBuildTask.java b/smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyBuildTask.java index 3e6a475..cdc3153 100644 --- a/smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyBuildTask.java +++ b/smithy-base/src/main/java/software/amazon/smithy/gradle/tasks/SmithyBuildTask.java @@ -12,6 +12,7 @@ import javax.inject.Inject; import org.gradle.StartParameter; import org.gradle.api.GradleException; +import org.gradle.api.file.Directory; import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.FileCollection; import org.gradle.api.model.ObjectFactory; @@ -165,4 +166,19 @@ public void execute() { getFork().get() ); } + + /** + * Convenience method to get the directory containing plugin artifacts. + * + * @param projection projection name + * @param plugin name of plugin to get artifact directory for + * + * @return provider for the plugin artifact directory + */ + public Provider getPluginProjectionDirectory(String projection, String plugin) { + return getProject().getLayout().dir( + getOutputDir().getAsFile() + .map(file -> SmithyUtils.getProjectionPluginPath(file, projection, plugin).toFile())); + } + }