Comments (13)
What you describe should work. What problem are you encountering when using transform-test
?
from byte-buddy.
I'm getting the following error when I execute mvn clean process-test-classes
:
[ERROR] Failed to execute goal net.bytebuddy:byte-buddy-maven-plugin:1.14.5:transform-test (default) on project <project name>: Cannot resolve plugin: <fqpn of a plugin in /src/test> -> [Help 1]
from byte-buddy.
Is the plugin included in the plugin's dependencies? It seems like a plugin fails to load. It should be added as a dependency to the plugin itself.
from byte-buddy.
@raphw Could you please elaborate? I'm not sure what do you mean.
from byte-buddy.
In Maven, are the plugins available using:
<plugin>
...
<dependencies>...</dependencies>
</plugin>
Or how are the plugins added to the build cycle.
from byte-buddy.
I add Byte Buddy plugins are into build cycle like so:
<!-- Byte Buddy plugins -->
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>${byte-buddy.version}</version>
<executions>
<execution>
<goals>
<goal>transform</goal>
<goal>transform-test</goal>
</goals>
</execution>
</executions>
<configuration>
<execution>
</execution>
<transformations>
<transformation>
<plugin>
<!-- fqpn of a plugin in /src/main is here !-->
</plugin>
</transformation>
<transformation>
<plugin>
<!-- fqpn of a plugin in /src/test is here !-->
</plugin>
</transformation>
</transformations>
</configuration>
</plugin>
from byte-buddy.
I think you need to define the plugin twice. Once transform for the plugin placed in main, once transform-test for the plugin placed in test. The test scope is not available while the main scope is resolved (and transformed).
from byte-buddy.
Unfortunately, I couldn't get it to work either. This is what I came up with:
<build>
<!-- other plugins -->
<!-- Byte Buddy plugins -->
<plugin>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-maven-plugin</artifactId>
<version>${byte-buddy.version}</version>
<executions>
<execution>
<id>main</id>
<goals>
<goal>transform</goal>
</goals>
<configuration>
<transformations>
<transformation>
<plugin>
<!-- fqpn of a plugin in /src/main -->
</plugin>
</transformation>
</transformations>
</configuration>
</execution>
<execution>
<id>test</id>
<goals>
<goal>transform-test</goal>
</goals>
<phase>process-test-classes</phase>
<configuration>
<transformations>
<transformation>
<plugin>
<!-- fqpn of a plugin in /src/test -->
</plugin>
</transformation>
</transformations>
</configuration>
</execution>
</executions>
</plugin>
</build>
Am I missing something here? Logically this should work, I'm binding my plugin to process-test-classes
phase explicitly, which by then should be able to see all my compiled test classes. I also have tried declaring byte-buddy-maven-plugin
twice, each with its own <execution>
, but it also fails (not to mention Maven giving a warning about using same plugin twice).
from byte-buddy.
That's how I'd do it and it works for me.
Could hou create a minimal reproducer?
from byte-buddy.
Sure, here it is: https://github.com/martyn0ff/bytebuddy-reproducer. I'm working with Spring Boot, so this is a minimal Spring Boot project which fails with same error (not sure if it may affect the result somehow).
from byte-buddy.
I see now what the issue is. The configuration refers to a Maven Coordinate. You would need to create a "test-jar" and then set:
<packaging>test-jar</packaging>
In the plugin-tag.
An easier option would however be to create a custom Maven module that includes your plugin and then configure it by setting
<artifactId>my-plugin-module</artifactId>
Alternatively, you can also activate class path discovery and load the plugin from a service. This would trigger both plugins during test, though.
from byte-buddy.
Thank you Rafael, this had worked very well. However now I am experiencing another issue - a ByteBuddy plugin that I wrote can not see classes that are located in test source folder. The plugin is supposed to scan test classes for annotations, find my custom annotation that takes takes an instance of Class<?>
as annotation attribute and perform some logic based on the class passed. If I pass a class that is located in source folder, everything is OK, but with classes from test source folder I am getting TypeNotFoundException
.
Failed to transform class com.acme.foo.TestClass using com.acme.foo.ByteBuddyPlugin8021e26: Type com.acme.foo.Baz not present -> [Help 1]
What can I do about it?
from byte-buddy.
Are you still using the transform-test goal? It's resolving the test class path: https://github.com/raphw/byte-buddy/blob/master/byte-buddy-maven-plugin/src/main/java/net/bytebuddy/build/maven/ByteBuddyMojo.java#L668
from byte-buddy.
Related Issues (20)
- Not able to intercept methods of java.net.HttpURLConnection class in Java 17 HOT 1
- Strange interaction with method implementations for methods from composite interfaces HOT 1
- Replace Method Code HOT 3
- Can I replace the new byte[] in the onTransformation method? HOT 1
- I want to use bytebuddy to advice java.time.LocalDateTime HOT 3
- BUG: instrumentation error HOT 3
- No classes have been predefined during the image build to load from bytecodes at runtime HOT 8
- Verify Error on Byte Buddy generated class HOT 1
- Question: copy class hierarchy in an environment without Java Agent HOT 1
- Can 'private final method' in 'public final class' be redefined? HOT 4
- Method matchers works by chance HOT 2
- Why does ClassNotFoundException appear in Interceptor when running in SpringBoot? HOT 1
- Compilation error after adding lombok to classpath HOT 1
- why is the byte-buudy AgentBuilder source code so long ? HOT 2
- Invalid module descriptor of byte-buddy `jar` when `JAVA_HOME` is set to version 21 HOT 16
- matched class wasn't transformered and the issue appears just twice, and i didn't reproducing the issue HOT 10
- Fail to read property due to `IllegalArgumentException` when using it on withX methods HOT 4
- Improve diagnostics/troubleshooting features for agent installation HOT 1
- ByteBudy agent required by Mockito fails to install on GraalVM HOT 1
- Error when trying to modify the response of a method assigned to a public static final config variable HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from byte-buddy.