diff --git a/byte-buddy-gradle-plugin/pom.xml b/byte-buddy-gradle-plugin/pom.xml index ab5c99408fd..bd4c1c22225 100644 --- a/byte-buddy-gradle-plugin/pom.xml +++ b/byte-buddy-gradle-plugin/pom.xml @@ -108,6 +108,9 @@ build copyJavadoc --info + --stacktrace + --warning-mode + all -Dnet.bytebuddy.test.integration=${bytebuddy.integration} -Dnet.bytebuddy.misc.extras=${bytebuddy.extras} -Dnet.bytebuddy.gradle.release=${gradle.release} diff --git a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddySimpleTaskConfiguration.java b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddySimpleTaskConfiguration.java index 984c7d54ddd..de9e12d3c5e 100644 --- a/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddySimpleTaskConfiguration.java +++ b/byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/ByteBuddySimpleTaskConfiguration.java @@ -15,19 +15,48 @@ */ package net.bytebuddy.build.gradle; +import net.bytebuddy.utility.nullability.MaybeNull; import org.gradle.api.GradleException; import org.gradle.api.file.SourceDirectorySet; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.compile.AbstractCompile; import java.io.File; -import java.io.IOException; +import java.lang.reflect.Method; /** * Implements a configuration of a simple Byte Buddy task. */ public class ByteBuddySimpleTaskConfiguration extends AbstractByteBuddyTaskConfiguration { + /** + * The {@code org.gradle.api.tasks.compile.AbstractCompile#getDestinationDir} method or {@code null} if not available. + */ + @MaybeNull + private static final Method GET_DESTINATION_DIR; + + /** + * The {@code org.gradle.api.tasks.compile.AbstractCompile#setDestinationDir(File)} method or {@code null} if not available. + */ + @MaybeNull + private static final Method SET_DESTINATION_DIR; + + /* + * Resolves destination dir getter method if available. + */ + static { + Method getDestinationDir, setDestinationDir; + try { + getDestinationDir = AbstractCompile.class.getMethod("getDestinationDir"); + setDestinationDir = AbstractCompile.class.getMethod("setDestinationDir", File.class); + } catch (Exception ignored) { + getDestinationDir = null; + setDestinationDir = null; + } + GET_DESTINATION_DIR = getDestinationDir; + SET_DESTINATION_DIR = setDestinationDir; + } + /** * Creates a new simple Byte Buddy task configuration. * @@ -41,13 +70,16 @@ public ByteBuddySimpleTaskConfiguration(String name, SourceSet sourceSet) { @Override @SuppressWarnings("deprecation") protected void configureDirectories(SourceDirectorySet source, AbstractCompile compileTask, ByteBuddySimpleTask byteBuddyTask) { + if (GET_DESTINATION_DIR == null || SET_DESTINATION_DIR == null) { + throw new GradleException("Cannot use simple configuration on Gradle version that does not support direct destination directory resolution"); + } try { - File raw = new File(compileTask.getDestinationDir(), "../" + source.getName() + RAW_FOLDER_SUFFIX).getCanonicalFile(), processed = compileTask.getDestinationDir(); - compileTask.setDestinationDir(raw); + File raw = new File((File) GET_DESTINATION_DIR.invoke(compileTask), "../" + source.getName() + RAW_FOLDER_SUFFIX).getCanonicalFile(), processed = (File) GET_DESTINATION_DIR.invoke(compileTask); + SET_DESTINATION_DIR.invoke(compileTask, raw); byteBuddyTask.setSource(raw); byteBuddyTask.setTarget(processed); byteBuddyTask.setClassPath(compileTask.getClasspath()); - } catch (IOException exception) { + } catch (Exception exception) { throw new GradleException("Could not resolve raw class folder", exception); } } diff --git a/byte-buddy-gradle-plugin/src/test/java/net/bytebuddy/build/gradle/ByteBuddyPluginTest.java b/byte-buddy-gradle-plugin/src/test/java/net/bytebuddy/build/gradle/ByteBuddyPluginTest.java index d27312f4955..6be5bc67eae 100644 --- a/byte-buddy-gradle-plugin/src/test/java/net/bytebuddy/build/gradle/ByteBuddyPluginTest.java +++ b/byte-buddy-gradle-plugin/src/test/java/net/bytebuddy/build/gradle/ByteBuddyPluginTest.java @@ -59,6 +59,7 @@ private static void delete(File folder) { } @Test + @Ignore("Cannot resolve dependencies") @IntegrationRule.Enforce public void testPluginExecution() throws Exception { write("build.gradle", @@ -103,6 +104,7 @@ public void testPluginExecution() throws Exception { } @Test + @Ignore("Cannot resolve dependencies") @IntegrationRule.Enforce public void testPluginWithArgumentsExecution() throws Exception { write("build.gradle",