@@ -78,15 +78,14 @@ public static IntegrationResult runIntegrations(BuildContext ctx) {
7878 for (ArtifactInfo art : ctx .resolveClassPath ().getArtifacts ()) {
7979 if (art .getCoordinate () != null ) { // skipping dependencies that does not have a GAV
8080 deps .put (art .getCoordinate ().toCanonicalForm (), art .getFile ());
81+ } else {
82+ deps .put (art .getFile ().getFileName ().toString (), art .getFile ());
8183 }
8284 }
8385
8486 List <String > comments = source .getTags ().map (s -> "//" + s ).collect (Collectors .toList ());
85- ClassLoader old = Thread .currentThread ().getContextClassLoader ();
8687 PrintStream oldout = System .out ;
87- try {
88- URLClassLoader integrationCl = getClassLoader (deps .values ());
89- Thread .currentThread ().setContextClassLoader (integrationCl );
88+ try (URLClassLoader integrationCl = getClassLoader (deps .values ())) {
9089 String requestedJavaVersion = prj .getJavaVersion ();
9190 Set <String > classNames = loadIntegrationClassNames (integrationCl );
9291 for (String className : classNames ) {
@@ -95,10 +94,12 @@ public static IntegrationResult runIntegrations(BuildContext ctx) {
9594 : null ;
9695 IntegrationInput input = new IntegrationInput (className , srcPath , compileDir , pomPath , repos , deps ,
9796 comments , prj .isNativeImage (), Util .isVerbose ());
98- IntegrationResult ir = requestedJavaVersion == null || JavaUtil .satisfiesRequestedVersion (
99- requestedJavaVersion , JavaUtil .getCurrentMajorJavaVersion ())
100- ? runIntegrationEmbedded (input , integrationCl )
101- : runIntegrationExternal (input , prj .getProperties (), prj .projectJdk ());
97+ boolean embedded = (requestedJavaVersion == null || JavaUtil .satisfiesRequestedVersion (
98+ requestedJavaVersion , JavaUtil .getCurrentMajorJavaVersion ()))
99+ && !"true" .equals (System .getProperty ("jbang.build.integration.forceExternal" ));
100+ IntegrationResult ir = embedded
101+ ? runIntegrationEmbedded (input , integrationCl )
102+ : runIntegrationExternal (input , prj .getProperties (), prj .projectJdk ());
102103 result = result .merged (ir );
103104 }
104105 } catch (ClassNotFoundException e ) {
@@ -111,7 +112,6 @@ public static IntegrationResult runIntegrations(BuildContext ctx) {
111112 } catch (Exception e ) {
112113 throw new ExitException (EXIT_GENERIC_ERROR , "Issue running postBuild()" , e );
113114 } finally {
114- Thread .currentThread ().setContextClassLoader (old );
115115 System .setOut (oldout );
116116 }
117117 return result ;
@@ -157,6 +157,17 @@ private static Set<String> loadIntegrationClassNames(URLClassLoader integrationC
157157
158158 private static IntegrationResult runIntegrationEmbedded (IntegrationInput input , URLClassLoader integrationCl )
159159 throws Exception {
160+ ClassLoader old = Thread .currentThread ().getContextClassLoader ();
161+ try {
162+ Thread .currentThread ().setContextClassLoader (integrationCl );
163+ return runIntegrationEmbedded_ (input , integrationCl );
164+ } finally {
165+ Thread .currentThread ().setContextClassLoader (old );
166+ }
167+ }
168+
169+ private static IntegrationResult runIntegrationEmbedded_ (IntegrationInput input , URLClassLoader integrationCl )
170+ throws Exception {
160171 Util .infoMsg ("Post build with " + input .integrationClassName );
161172
162173 if (input .source != null ) {
0 commit comments