|
6 | 6 | package software.amazon.smithy.gradle.internal; |
7 | 7 |
|
8 | 8 | import java.io.File; |
| 9 | +import java.util.HashMap; |
| 10 | +import java.util.Map; |
9 | 11 | import java.util.Optional; |
10 | 12 | import org.gradle.api.GradleException; |
11 | 13 | import org.gradle.api.Project; |
|
25 | 27 | public final class CliDependencyResolver { |
26 | 28 | private static final String DEPENDENCY_NOTATION = "software.amazon.smithy:smithy-cli:%s"; |
27 | 29 | 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 | + } |
28 | 36 |
|
29 | 37 | private CliDependencyResolver() {} |
30 | 38 |
|
@@ -60,8 +68,7 @@ public static String resolve(Project project) { |
60 | 68 | return explicitCliDepOptional.get().getVersion(); |
61 | 69 | } |
62 | 70 |
|
63 | | - // Force projects in the main smithy repo to use an explicit smithy cli dependency |
64 | | - failIfRunningInMainSmithyRepo(project); |
| 71 | + checkIfRunningInMainSmithyRepo(project); |
65 | 72 |
|
66 | 73 | // If no explicit dependency was found, find the CLI version by scanning and set this as a dependency |
67 | 74 | String cliVersion = getCliVersion(project); |
@@ -124,16 +131,17 @@ private static String scanForSmithyCliVersion(Project project) { |
124 | 131 | + "explicit dependency on smithy-model."); |
125 | 132 | } |
126 | 133 |
|
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) { |
130 | 136 | if (project.getParent() != null) { |
131 | 137 | Project parent = project.getParent(); |
132 | 138 | if (parent.getGroup().equals("software.amazon.smithy")) { |
133 | 139 | for (Project subproject : parent.getSubprojects()) { |
134 | 140 | 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)"); |
137 | 145 | } |
138 | 146 | } |
139 | 147 | } |
|
0 commit comments