|
37 | 37 | */ |
38 | 38 | @Component |
39 | 39 | public class DepsShellCommand extends StdShellCommand { |
| 40 | + private static final String MVN_COMMAND = "mvn"; |
| 41 | + |
40 | 42 | public DepsShellCommand() { |
41 | 43 | super(ImmutableList.of("deps"), "deps related commands: install / update / manage app dependencies"); |
42 | 44 | } |
@@ -154,16 +156,25 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx |
154 | 156 |
|
155 | 157 | // Then copying dependencies through copy-dependencies plugin |
156 | 158 | ProcessBuilder mavenCmd = new ProcessBuilder( |
157 | | - "mvn", "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies", |
| 159 | + MVN_COMMAND, "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies", |
158 | 160 | "-DoutputDirectory=" + dependenciesDir.toAbsolutePath(), "-DincludeScope=runtime" |
159 | 161 | ); |
160 | 162 |
|
161 | 163 | shell.println("Executing `"+mavenCmd+"` ..."); |
162 | | - mavenCmd.redirectErrorStream(true) |
163 | | - .redirectOutput(ProcessBuilder.Redirect.INHERIT) |
164 | | - .directory(shell.currentLocation().toFile().getAbsoluteFile()) |
165 | | - .start() |
166 | | - .waitFor(); |
| 164 | + try { |
| 165 | + mavenCmd.redirectErrorStream(true) |
| 166 | + .redirectOutput(ProcessBuilder.Redirect.INHERIT) |
| 167 | + .directory(shell.currentLocation().toFile().getAbsoluteFile()) |
| 168 | + .start() |
| 169 | + .waitFor(); |
| 170 | + } catch(IOException e) { |
| 171 | + if(e.getMessage().startsWith(String.format("Cannot run program \"%s\"", MVN_COMMAND))) { |
| 172 | + shell.println("Looks like mvn is not installed here ... trying to fallback installing pom.xml file with Ivy..."); |
| 173 | + installDepsFromIvyDescriptor(shell, pomFile); |
| 174 | + } else { |
| 175 | + Throwables.propagate(e); |
| 176 | + } |
| 177 | + } |
167 | 178 | } |
168 | 179 |
|
169 | 180 | private static void storeModuleDescriptorMD5File(RestxShell shell, ModuleDescriptorType mdType) throws IOException { |
|
0 commit comments