Skip to content

Commit 376de01

Browse files
committed
Don't remove @GrabResolver in JarCommand, disable initClass instead
Previously, JarCommand removed all @GrabResolver annotations in an AST transformation. This was being performed as custom resolver configuration is not necessary in a jar as all of the dependencies are available from the jar. Furthermore, leaving the annotations in place caused a failure when the jar was run due to a missing Ivy dependency that's required by Groovy's default GrapeEngine, GrapeIvy. The removal of @GrabResolver annotations was being done before they could be used by Groovy's GrabAnnotationTransformation to configure the GrapeEngine's resolvers. This resulted in the annotations having no effect such that a dependency that was only available from a repository made available by @GrabResolver would fail to resolve if it was not cached locally. This commit updates the AST transformation to leave the @GrabResolver annotations in place but to set their initClass attribute to false. This allows the annotation to be used while the jar's being compiled, but supresses the generation of the static initializer that adds the custom resolver to the GrapeEngine when the compiled code's run via java -jar. Fixes gh-2330
1 parent 9744d28 commit 376de01

File tree

1 file changed

+7
-6
lines changed
  • spring-boot-cli/src/main/java/org/springframework/boot/cli/command/jar

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2014 the original author or authors.
2+
* Copyright 2012-2015 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -280,18 +280,19 @@ private void visitModule(ModuleNode module) {
280280
// We only need to do it at most once
281281
break;
282282
}
283-
// Remove GrabReolvers because all the dependencies are local now
284-
removeGrabResolver(module.getClasses());
285-
removeGrabResolver(module.getImports());
283+
// Disable the addition of a static initializer that calls Grape.addResolver
284+
// because all the dependencies are local now
285+
disableGrabResolvers(module.getClasses());
286+
disableGrabResolvers(module.getImports());
286287
}
287288

288-
private void removeGrabResolver(List<? extends AnnotatedNode> nodes) {
289+
private void disableGrabResolvers(List<? extends AnnotatedNode> nodes) {
289290
for (AnnotatedNode classNode : nodes) {
290291
List<AnnotationNode> annotations = classNode.getAnnotations();
291292
for (AnnotationNode node : new ArrayList<AnnotationNode>(annotations)) {
292293
if (node.getClassNode().getNameWithoutPackage()
293294
.equals("GrabResolver")) {
294-
annotations.remove(node);
295+
node.setMember("initClass", new ConstantExpression(false));
295296
}
296297
}
297298
}

0 commit comments

Comments
 (0)