GithubHelp home page GithubHelp logo

Comments (13)

raphw avatar raphw commented on July 28, 2024

What you describe should work. What problem are you encountering when using transform-test?

from byte-buddy.

martyn0ff avatar martyn0ff commented on July 28, 2024

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.

raphw avatar raphw commented on July 28, 2024

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.

martyn0ff avatar martyn0ff commented on July 28, 2024

@raphw Could you please elaborate? I'm not sure what do you mean.

from byte-buddy.

raphw avatar raphw commented on July 28, 2024

In Maven, are the plugins available using:

<plugin>
  ...
  <dependencies>...</dependencies>
</plugin>

Or how are the plugins added to the build cycle.

from byte-buddy.

martyn0ff avatar martyn0ff commented on July 28, 2024

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.

raphw avatar raphw commented on July 28, 2024

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.

martyn0ff avatar martyn0ff commented on July 28, 2024

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.

raphw avatar raphw commented on July 28, 2024

That's how I'd do it and it works for me.

Could hou create a minimal reproducer?

from byte-buddy.

martyn0ff avatar martyn0ff commented on July 28, 2024

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.

raphw avatar raphw commented on July 28, 2024

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.

martyn0ff avatar martyn0ff commented on July 28, 2024

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.

raphw avatar raphw commented on July 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.