Skip to content

Commit c15c880

Browse files
committed
Clean up build and remove access to projects from Maven and Gradle plugins as this breaks configuration cache.
1 parent efbd6cb commit c15c880

File tree

5 files changed

+23
-21
lines changed

5 files changed

+23
-21
lines changed

byte-buddy-gradle-plugin/android-plugin/src/main/java/net/bytebuddy/build/gradle/android/ByteBuddyLocalClassesEnhancerTask.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.gradle.api.DefaultTask;
3030
import org.gradle.api.GradleException;
3131
import org.gradle.api.JavaVersion;
32-
import org.gradle.api.Project;
3332
import org.gradle.api.file.*;
33+
import org.gradle.api.logging.Logger;
3434
import org.gradle.api.provider.ListProperty;
3535
import org.gradle.api.provider.Property;
3636
import org.gradle.api.tasks.*;
@@ -226,7 +226,7 @@ public void execute() throws IOException {
226226
try {
227227
Class<?> discovery = Class.forName("net.bytebuddy.build.gradle.Discovery");
228228
Class.forName("net.bytebuddy.build.gradle.AbstractByteBuddyTask").getMethod("apply",
229-
Project.class,
229+
Logger.class,
230230
ClassLoader.class,
231231
List.class,
232232
discovery,
@@ -245,7 +245,7 @@ public void execute() throws IOException {
245245
boolean.class,
246246
Plugin.Engine.Source.class,
247247
Plugin.Engine.Target.class).invoke(null,
248-
getProject(),
248+
getLogger(),
249249
classLoader,
250250
transformations,
251251
discovery.getMethod("valueOf", String.class).invoke(null, getDiscovery().get().name()),

byte-buddy-gradle-plugin/common.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if (Boolean.getBoolean('net.bytebuddy.misc.extras')) {
8787
}
8888
javadoc {
8989
options {
90-
links 'https://docs.oracle.com/javase/1.5.0/docs/api'
90+
links 'https://docs.oracle.com/javase/6/docs/api'
9191
links 'https://docs.gradle.org/7.5/javadoc'
9292
linksOffline "https://javadoc.io/doc/net.bytebuddy/byte-buddy/${pom.parent.version.text().toString()}", '../byte-buddy/target/apidocs'
9393
}

byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTask.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import net.bytebuddy.utility.nullability.UnknownNull;
2828
import org.gradle.api.Action;
2929
import org.gradle.api.DefaultTask;
30-
import org.gradle.api.Project;
3130
import org.gradle.api.logging.Logger;
3231
import org.gradle.api.tasks.Input;
3332
import org.gradle.api.tasks.Internal;
@@ -400,7 +399,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
400399
classFileVersion = this.classFileVersion;
401400
getLogger().debug("Java version was configured: {}", classFileVersion.getJavaVersion());
402401
}
403-
apply(getProject(),
402+
apply(getLogger(),
404403
getClass().getClassLoader(),
405404
new ArrayList<Transformation>(getTransformations()),
406405
getDiscovery(),
@@ -424,7 +423,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
424423
/**
425424
* Dispatches a Byte Buddy instrumentation Gradle task.
426425
*
427-
* @param project The current project.
426+
* @param logger The logger to use.
428427
* @param rootLoader The class loader that is used for searching types and applying plugins.
429428
* @param transformations The transformations to apply.
430429
* @param discovery The discovery for plugins to use.
@@ -445,7 +444,7 @@ protected void doApply(Plugin.Engine.Source source, Plugin.Engine.Target target)
445444
* @param target The target to use for instrumenting.
446445
* @throws IOException If an I/O error occurs.
447446
*/
448-
public static void apply(Project project,
447+
public static void apply(Logger logger,
449448
ClassLoader rootLoader,
450449
List<Transformation> transformations,
451450
Discovery discovery,
@@ -485,16 +484,16 @@ public static void apply(Project project,
485484
} catch (ClassNotFoundException exception) {
486485
throw new IllegalStateException("Discovered plugin is not available: " + name, exception);
487486
}
488-
project.getLogger().debug("Registered discovered plugin: {}", name);
487+
logger.debug("Registered discovered plugin: {}", name);
489488
} else {
490-
project.getLogger().info("Skipping discovered plugin {} which was previously discovered or registered", name);
489+
logger.info("Skipping discovered plugin {} which was previously discovered or registered", name);
491490
}
492491
}
493492
}
494493
if (transformations.isEmpty()) {
495-
project.getLogger().warn("No transformations are specified or discovered. Application will be non-operational.");
494+
logger.warn("No transformations are specified or discovered. Application will be non-operational.");
496495
} else {
497-
project.getLogger().debug("{} plugins are being applied via configuration and discovery", transformations.size());
496+
logger.debug("{} plugins are being applied via configuration and discovery", transformations.size());
498497
}
499498
List<File> classPath = new ArrayList<File>();
500499
for (File file : artifacts) {
@@ -506,12 +505,11 @@ public static void apply(Project project,
506505
factories.add(new Plugin.Factory.UsingReflection(transformation.toPlugin(classLoader))
507506
.with(transformation.makeArgumentResolvers())
508507
.with(rootLocationResolver,
509-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, project.getLogger()),
510-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, project.getLogger()),
511-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(project.getLogger())),
512-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Project.class, project),
508+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Logger.class, logger),
509+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(org.slf4j.Logger.class, logger),
510+
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new GradleBuildLogger(logger)),
513511
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, classPath.toArray(new File[0]))));
514-
project.getLogger().info("Resolved plugin: {}", transformation.toPluginName());
512+
logger.info("Resolved plugin: {}", transformation.toPluginName());
515513
} catch (Throwable throwable) {
516514
throw new IllegalStateException("Cannot resolve plugin: " + transformation.toPluginName(), throwable);
517515
}
@@ -533,7 +531,7 @@ public static void apply(Project project,
533531
: Plugin.Engine.PoolStrategy.Default.FAST)
534532
.with(classFileLocator)
535533
.with(multiReleaseClassFileVersion)
536-
.with(new TransformationLogger(project.getLogger()))
534+
.with(new TransformationLogger(logger))
537535
.withErrorHandlers(Plugin.Engine.ErrorHandler.Enforcing.ALL_TYPES_RESOLVED, failOnLiveInitializer
538536
? Plugin.Engine.ErrorHandler.Enforcing.NO_LIVE_INITIALIZERS
539537
: Plugin.Engine.Listener.NoOp.INSTANCE, failFast
@@ -554,9 +552,9 @@ public static void apply(Project project,
554552
if (!summary.getFailed().isEmpty()) {
555553
throw new IllegalStateException(summary.getFailed() + " type transformation(s) have failed");
556554
} else if (warnOnEmptyTypeSet && summary.getTransformed().isEmpty()) {
557-
project.getLogger().warn("No types were transformed during plugin execution");
555+
logger.warn("No types were transformed during plugin execution");
558556
} else {
559-
project.getLogger().info("Transformed {} type(s)", summary.getTransformed().size());
557+
logger.info("Transformed {} type(s)", summary.getTransformed().size());
560558
}
561559
}
562560

byte-buddy-gradle-plugin/src/main/java/net/bytebuddy/build/gradle/AbstractByteBuddyTaskExtension.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,11 @@ protected void configure(T task) {
482482
doConfigure(task);
483483
}
484484

485+
/**
486+
* Defines the discovery set to use.
487+
*
488+
* @param fileCollection The file collection that represents the discovery set.
489+
*/
485490
protected abstract void discoverySet(FileCollection fileCollection);
486491

487492
/**

byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ protected Plugin.Engine.Summary transform(List<? extends String> classPath,
389389
.with(Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File.class, file),
390390
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(Log.class, getLog()),
391391
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(BuildLogger.class, new MavenBuildLogger(getLog())),
392-
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(MavenProject.class, project),
393392
Plugin.Factory.UsingReflection.ArgumentResolver.ForType.of(File[].class, artifacts.toArray(new File[0]))));
394393
getLog().info("Resolved plugin: " + plugin);
395394
} catch (Throwable throwable) {

0 commit comments

Comments
 (0)