Byte buddy maven plugin fails in modularized projects
My project fails to run byte-buddy-maven-plugin because it has a module-info.java file in the sources.
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>1.12.12</version>
<executions>
<execution>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformations>
<transformation>
<plugin>reactor.tools.agent.ReactorDebugByteBuddyPlugin</plugin>
</transformation>
</transformations>
</configuration>
</plugin>
java.lang.IllegalStateException: Illegal type name: module-info for class module-info
at net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated (InstrumentedType.java:1553)
at net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare (MethodRegistry.java:520)
at net.bytebuddy.dynamic.scaffold.inline.RebaseDynamicTypeBuilder.make (RebaseDynamicTypeBuilder.java:221)
at net.bytebuddy.build.Plugin$Engine$Default$Preprocessor$Resolved.call (Plugin.java:4664)
at net.bytebuddy.build.Plugin$Engine$Default$Preprocessor$Resolved.call (Plugin.java:4621)
at net.bytebuddy.build.Plugin$Engine$Dispatcher$ForSerialTransformation.accept (Plugin.java:3704)
at net.bytebuddy.build.Plugin$Engine$Default.apply (Plugin.java:4468)
at net.bytebuddy.build.maven.ByteBuddyMojo.apply (ByteBuddyMojo.java:422)
at net.bytebuddy.build.maven.ByteBuddyMojo.execute (ByteBuddyMojo.java:287)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
at java.lang.reflect.Method.invoke (Method.java:577)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
at org.codehaus.classworlds.Launcher.main (Launcher.java:47)
You are right, module-info should be skipped. I changed this on master and will release the fix with the next version.
@raphw Where can I find the documentation for this Maven Plugin?
Its a "plugin-plugin" and documented in the readme for the subproject.
@raphw
`private static void transformHibernatePersistentCollection() {
log.info("Transforming org.hibernate.collection.internal.AbstractPersistentCollection"
+ "#initialize()");
new AgentBuilder
.Default()
.type(named("org.hibernate.collection.internal.AbstractPersistentCollection"))
.transform(new AgentBuilder.Transformer() {
@Override
public DynamicType
.Builder<?> transform(DynamicType.Builder<?> builder,
TypeDescription typeDescription,
ClassLoader classLoader,
JavaModule module) {
return builder
.method(named("initialize"))
.intercept(Advice
.to(ApplyEntityGraphOnInitializingPersistentCollection.class));
}
})
.installOnByteBuddyAgent();
}`
I have this transformation which is being done during runtime. Is there a way to move this to compile time using the maven plugin ? Can you provide few examples ?
Unfortunately, no, unless within the Hibernate build. Build plugins can only transform your own classes.