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 gh-1179
This commit is contained in:
parent
981669b7c0
commit
179ac6022a
|
|
@ -59,6 +59,23 @@ public class JarCommandIT {
|
||||||
+ "resulting jar and at least one source file must be specified"));
|
+ "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
|
@Test
|
||||||
public void jarCreation() throws Exception {
|
public void jarCreation() throws Exception {
|
||||||
File jar = new File("target/test-app.jar");
|
File jar = new File("target/test-app.jar");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
@GrabResolver(name='clojars.org', root='http://clojars.org/repo')
|
||||||
|
@Grab('redis.embedded:embedded-redis:0.2')
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class EmbeddedRedis {
|
||||||
|
}
|
||||||
|
|
@ -35,6 +35,7 @@ import joptsimple.OptionSet;
|
||||||
import joptsimple.OptionSpec;
|
import joptsimple.OptionSpec;
|
||||||
|
|
||||||
import org.codehaus.groovy.ast.ASTNode;
|
import org.codehaus.groovy.ast.ASTNode;
|
||||||
|
import org.codehaus.groovy.ast.AnnotatedNode;
|
||||||
import org.codehaus.groovy.ast.AnnotationNode;
|
import org.codehaus.groovy.ast.AnnotationNode;
|
||||||
import org.codehaus.groovy.ast.ClassNode;
|
import org.codehaus.groovy.ast.ClassNode;
|
||||||
import org.codehaus.groovy.ast.ModuleNode;
|
import org.codehaus.groovy.ast.ModuleNode;
|
||||||
|
|
@ -279,6 +280,21 @@ public class JarCommand extends OptionParsingCommand {
|
||||||
// We only need to do it at most once
|
// We only need to do it at most once
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// Remove GrabReolvers because all the dependencies are local now
|
||||||
|
removeGrabResolver(module.getClasses());
|
||||||
|
removeGrabResolver(module.getImports());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeGrabResolver(List<? extends AnnotatedNode> nodes) {
|
||||||
|
for (AnnotatedNode classNode : nodes) {
|
||||||
|
List<AnnotationNode> annotations = classNode.getAnnotations();
|
||||||
|
for (AnnotationNode node : new ArrayList<AnnotationNode>(annotations)) {
|
||||||
|
if (node.getClassNode().getNameWithoutPackage()
|
||||||
|
.equals("GrabResolver")) {
|
||||||
|
annotations.remove(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue