diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java index 6542e25cab..e795fcd71d 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java @@ -59,6 +59,23 @@ public class JarCommandIT { + "resulting jar and at least one source file must be specified")); } + @Test + public void jarCreationWithGrabResolver() throws Exception { + File jar = new File("target/test-app.jar"); + Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), + "bad.groovy"); + invocation.await(); + assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length()); + assertTrue(jar.exists()); + + Process process = new JavaExecutable().processBuilder("-jar", + jar.getAbsolutePath()).start(); + invocation = new Invocation(process); + invocation.await(); + + assertThat(invocation.getErrorOutput(), equalTo("")); + } + @Test public void jarCreation() throws Exception { File jar = new File("target/test-app.jar"); diff --git a/spring-boot-cli/src/it/resources/jar-command/bad.groovy b/spring-boot-cli/src/it/resources/jar-command/bad.groovy new file mode 100644 index 0000000000..6d4be26b8f --- /dev/null +++ b/spring-boot-cli/src/it/resources/jar-command/bad.groovy @@ -0,0 +1,6 @@ +@GrabResolver(name='clojars.org', root='http://clojars.org/repo') +@Grab('redis.embedded:embedded-redis:0.2') + +@Component +class EmbeddedRedis { +} \ No newline at end of file diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java index eb2be18dd1..5e58aea461 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java @@ -35,6 +35,7 @@ import joptsimple.OptionSet; import joptsimple.OptionSpec; import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.groovy.ast.AnnotatedNode; import org.codehaus.groovy.ast.AnnotationNode; import org.codehaus.groovy.ast.ClassNode; import org.codehaus.groovy.ast.ModuleNode; @@ -279,6 +280,21 @@ public class JarCommand extends OptionParsingCommand { // We only need to do it at most once break; } + // Remove GrabReolvers because all the dependencies are local now + removeGrabResolver(module.getClasses()); + removeGrabResolver(module.getImports()); + } + + private void removeGrabResolver(List nodes) { + for (AnnotatedNode classNode : nodes) { + List annotations = classNode.getAnnotations(); + for (AnnotationNode node : new ArrayList(annotations)) { + if (node.getClassNode().getNameWithoutPackage() + .equals("GrabResolver")) { + annotations.remove(node); + } + } + } } }