Skip to content

Commit 2d1b896

Browse files
authored
Use smithy-cli as project dependency when plugin used within smithy repository (#151)
1 parent 0ca9089 commit 2d1b896

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

smithy-base/src/main/java/software/amazon/smithy/gradle/internal/CliDependencyResolver.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
package software.amazon.smithy.gradle.internal;
77

88
import java.io.File;
9+
import java.util.HashMap;
10+
import java.util.Map;
911
import java.util.Optional;
1012
import org.gradle.api.GradleException;
1113
import org.gradle.api.Project;
@@ -25,6 +27,12 @@
2527
public final class CliDependencyResolver {
2628
private static final String DEPENDENCY_NOTATION = "software.amazon.smithy:smithy-cli:%s";
2729
private static final String SMITHY_CLI_DEP_NAME = "smithy-cli";
30+
private static final Map<String, String> SMITHY_CLI_PROJECT_CONFIGURATION = new HashMap<>();
31+
32+
static {
33+
SMITHY_CLI_PROJECT_CONFIGURATION.put("path", ":smithy-cli");
34+
SMITHY_CLI_PROJECT_CONFIGURATION.put("configuration", "shadow");
35+
}
2836

2937
private CliDependencyResolver() {}
3038

@@ -60,8 +68,7 @@ public static String resolve(Project project) {
6068
return explicitCliDepOptional.get().getVersion();
6169
}
6270

63-
// Force projects in the main smithy repo to use an explicit smithy cli dependency
64-
failIfRunningInMainSmithyRepo(project);
71+
checkIfRunningInMainSmithyRepo(project);
6572

6673
// If no explicit dependency was found, find the CLI version by scanning and set this as a dependency
6774
String cliVersion = getCliVersion(project);
@@ -124,16 +131,17 @@ private static String scanForSmithyCliVersion(Project project) {
124131
+ "explicit dependency on smithy-model.");
125132
}
126133

127-
// Subprojects in the main Smithy repo must define an explicit smithy-cli dependency.
128-
// This is mainly because I couldn't figure out how to add a project dependency.
129-
private static void failIfRunningInMainSmithyRepo(Project project) {
134+
// Check if plugin is being run in the main smithy repo, and, if so, intrinsically depend on the CLI
135+
private static void checkIfRunningInMainSmithyRepo(Project project) {
130136
if (project.getParent() != null) {
131137
Project parent = project.getParent();
132138
if (parent.getGroup().equals("software.amazon.smithy")) {
133139
for (Project subproject : parent.getSubprojects()) {
134140
if (subproject.getPath().equals(":smithy-cli")) {
135-
throw new GradleException("Detected that this is the main Smithy repo. "
136-
+ "You need to add an explicit :project dependency on :smithy-cli");
141+
// Add a dependency on the smithy-cli, shadow configuration
142+
project.getDependencies().project(SMITHY_CLI_PROJECT_CONFIGURATION);
143+
project.getLogger().info("Detected that this is the main Smithy repo. "
144+
+ "Adding dependency on (:smithy-cli - shadow)");
137145
}
138146
}
139147
}

0 commit comments

Comments
 (0)