Skip to content

Commit 179ac60

Browse files
author
Dave Syer
committed
Remove @GrabResolvers before packaging jar in CLI
Since all dependencies are local in a jar there is no need for a GrabResolver (and it breaks the app because the default ivy GrapeEngine is used instead of the smart, pretty Boot one). Fixes spring-projectsgh-1179
1 parent 981669b commit 179ac60

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

spring-boot-cli/src/it/java/org/springframework/boot/cli/JarCommandIT.java

+17
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ public void noSources() throws Exception {
5959
+ "resulting jar and at least one source file must be specified"));
6060
}
6161

62+
@Test
63+
public void jarCreationWithGrabResolver() throws Exception {
64+
File jar = new File("target/test-app.jar");
65+
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
66+
"bad.groovy");
67+
invocation.await();
68+
assertEquals(invocation.getErrorOutput(), 0, invocation.getErrorOutput().length());
69+
assertTrue(jar.exists());
70+
71+
Process process = new JavaExecutable().processBuilder("-jar",
72+
jar.getAbsolutePath()).start();
73+
invocation = new Invocation(process);
74+
invocation.await();
75+
76+
assertThat(invocation.getErrorOutput(), equalTo(""));
77+
}
78+
6279
@Test
6380
public void jarCreation() throws Exception {
6481
File jar = new File("target/test-app.jar");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@GrabResolver(name='clojars.org', root='http://clojars.org/repo')
2+
@Grab('redis.embedded:embedded-redis:0.2')
3+
4+
@Component
5+
class EmbeddedRedis {
6+
}

spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar/JarCommand.java

+16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import joptsimple.OptionSpec;
3636

3737
import org.codehaus.groovy.ast.ASTNode;
38+
import org.codehaus.groovy.ast.AnnotatedNode;
3839
import org.codehaus.groovy.ast.AnnotationNode;
3940
import org.codehaus.groovy.ast.ClassNode;
4041
import org.codehaus.groovy.ast.ModuleNode;
@@ -279,6 +280,21 @@ private void visitModule(ModuleNode module) {
279280
// We only need to do it at most once
280281
break;
281282
}
283+
// Remove GrabReolvers because all the dependencies are local now
284+
removeGrabResolver(module.getClasses());
285+
removeGrabResolver(module.getImports());
286+
}
287+
288+
private void removeGrabResolver(List<? extends AnnotatedNode> nodes) {
289+
for (AnnotatedNode classNode : nodes) {
290+
List<AnnotationNode> annotations = classNode.getAnnotations();
291+
for (AnnotationNode node : new ArrayList<AnnotationNode>(annotations)) {
292+
if (node.getClassNode().getNameWithoutPackage()
293+
.equals("GrabResolver")) {
294+
annotations.remove(node);
295+
}
296+
}
297+
}
282298
}
283299

284300
}

0 commit comments

Comments
 (0)