From 423b13b50ae7940c11807a4b8c545d16a12e8059 Mon Sep 17 00:00:00 2001 From: Markus Heiden Date: Tue, 8 Jun 2021 01:01:06 +0200 Subject: [PATCH] HHH-14657 Use the compile instead of runtime classpath The runtime classpath contains the dependencies as jars that are not yet built when the plugin needs them. So use the compile classpath plus the compiled classes of the current project. --- .../orm/tooling/gradle/EnhancementHelper.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhancementHelper.java b/tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhancementHelper.java index 927fa254e5..85982c8c5b 100644 --- a/tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhancementHelper.java +++ b/tooling/hibernate-gradle-plugin/src/main/groovy/org/hibernate/orm/tooling/gradle/EnhancementHelper.java @@ -37,7 +37,7 @@ */ public class EnhancementHelper { static void enhance(SourceSet sourceSet, EnhanceExtension options, Project project) { - final ClassLoader classLoader = toClassLoader( sourceSet.getRuntimeClasspath() ); + final ClassLoader classLoader = toClassLoader( sourceSet.getCompileClasspath(), sourceSet.getOutput().getClassesDirs() ); final EnhancementContext enhancementContext = new DefaultEnhancementContext() { @Override @@ -96,14 +96,16 @@ public boolean doExtendedEnhancement(UnloadedClass classDescriptor) { } } - public static ClassLoader toClassLoader(FileCollection runtimeClasspath) { + public static ClassLoader toClassLoader(FileCollection... classpaths) { List urls = new ArrayList<>(); - for ( File file : runtimeClasspath ) { - try { - urls.add( file.toURI().toURL() ); - } - catch (MalformedURLException e) { - throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e ); + for ( FileCollection classpath : classpaths ) { + for ( File file : classpath ) { + try { + urls.add( file.toURI().toURL() ); + } + catch (MalformedURLException e) { + throw new GradleException( "Unable to resolve classpath entry to URL : " + file.getAbsolutePath(), e ); + } } } return new URLClassLoader( urls.toArray( new URL[0] ), Enhancer.class.getClassLoader() );