From 5cc5c73e23b099715b1d631ff9c860e8fc0beec3 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Wed, 25 Sep 2024 18:39:23 +0200 Subject: [PATCH] Respect class file version also in Android plugins when resolving class files. --- .../gradle/android/ByteBuddyAndroidService.java | 12 ++++++------ .../LegacyByteBuddyLocalClassesEnhancerTask.java | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidService.java b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidService.java index 275235da56a..e1f1d98ea90 100644 --- a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidService.java +++ b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyAndroidService.java @@ -99,6 +99,10 @@ public void initialize(ByteBuddyInstrumentationParameters parameters) { return; } try { + ClassFileVersion classFileVersion = ClassFileVersion.ofJavaVersionString(getParameters() + .getJavaTargetCompatibilityVersion() + .get() + .toString()); List classFileLocators = new ArrayList(); classFileLocators.add(ClassFileLocator.ForClassLoader.of(ByteBuddy.class.getClassLoader())); for (File artifact : parameters.getRuntimeClasspath() @@ -106,13 +110,9 @@ public void initialize(ByteBuddyInstrumentationParameters parameters) { .plus(parameters.getByteBuddyClasspath()) .getFiles()) { classFileLocators.add(artifact.isFile() - ? ClassFileLocator.ForJarFile.of(artifact) - : new ClassFileLocator.ForFolder(artifact)); + ? ClassFileLocator.ForJarFile.of(artifact, classFileVersion) + : ClassFileLocator.ForFolder.of(artifact, classFileVersion)); } - ClassFileVersion classFileVersion = ClassFileVersion.ofJavaVersionString(getParameters() - .getJavaTargetCompatibilityVersion() - .get() - .toString()); ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators); TypePool typePool = Plugin.Engine.PoolStrategy.Default.FAST.typePool(classFileLocator); ClassLoader classLoader = new URLClassLoader( diff --git a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/LegacyByteBuddyLocalClassesEnhancerTask.java b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/LegacyByteBuddyLocalClassesEnhancerTask.java index 335edf5b572..9062a8a28e3 100644 --- a/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/LegacyByteBuddyLocalClassesEnhancerTask.java +++ b/byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/LegacyByteBuddyLocalClassesEnhancerTask.java @@ -130,8 +130,8 @@ public void execute() { List classFileLocators = new ArrayList(); for (File file : getRuntimeClasspath().plus(getAndroidBootClasspath()).plus(getByteBuddyClasspath()).getFiles()) { classFileLocators.add(file.isFile() - ? ClassFileLocator.ForJarFile.of(file) - : new ClassFileLocator.ForFolder(file)); + ? ClassFileLocator.ForJarFile.of(file, classFileVersion) + : ClassFileLocator.ForFolder.of(file, classFileVersion)); } classFileLocators.add(ClassFileLocator.ForClassLoader.of(ByteBuddy.class.getClassLoader())); ClassFileLocator classFileLocator = new ClassFileLocator.Compound(classFileLocators); @@ -173,6 +173,7 @@ public void execute() { classFileVersion, MethodNameTransformer.Suffixing.withRandomSuffix()) .with(classFileLocator) + .with(classFileVersion) .apply(new Plugin.Engine.Source.Compound(sources), new Plugin.Engine.Target.ForFolder(getOutputDir().get().getAsFile()), factories); if (!summary.getFailed().isEmpty()) { throw new IllegalStateException(summary.getFailed() + " local type transformations have failed");