Class ByteBuddyMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
ByteBuddyMojo.ForDependencyFolder, ByteBuddyMojo.ForExplicitLocations, ByteBuddyMojo.ForLifecycleTypes
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA coordinate to locate a managed dependency.private static classMatches elements which represent a Java class that is represented in the list or an inner class of the classes represented in the list.static classTransforms all jars for a folder containing jar files, typically project dependencies.static classTransforms specified classes from files in a folder or a jar file to a folder or jar file.static classA version of the plugin that is bound to Maven's lifecycle.protected static classABuildLoggerimplementation for a MavenLog.protected static classA filter for files that were written before a given timestamp, to avoid duplicate application.protected static classAPlugin.Engine.Listenerthat logs several relevant events during the build.protected static classA transformer that is applied during the plugin's execution. -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanScans the class path (or test class path) for Byte Buddy plugins to apply.Determines if the build should discover Byte Buddy build plugins on this Maven plugin's class loader.org.apache.maven.plugin.MojoExecutionThe current execution of this plugin.booleanWhen set totrue, the debug information of class files should be parsed to extract parameter names.booleanWhen set totrue, this mojo fails immediately if a plugin cannot be applied.booleanWhen transforming classes during build time, it is not possible to apply any transformations which require a class in its loaded state.The initializer used for creating aByteBuddyinstance and for applying a transformation.private static final StringThe file extension for Java source files.Defines the version to use for resolving multi-release jar files.org.apache.maven.project.MavenProjectThe Maven project.org.eclipse.aether.RepositorySystemThe currently used repository system.org.eclipse.aether.RepositorySystemSessionThe currently used system session for the repository system.booleanWhen set totrue, this mojo is not applied to the current module.intDetermines the tolerance of many milliseconds between this plugin run and the last edit are permitted for considering a file as stale if the plugin was executed before.Specifies the method name suffix that is used when type's method need to be rebased.intIndicates the amount of threads used for parallel type processing or0for serial processing.The list of transformations.booleanWhen set totrue, this mojo warns of not having transformed any types.booleanWhen set totrue, this mojo warns of an non-existent output directory.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidapply(List<ByteBuddyMojo.Transformer> transformers, List<String> elements, Map<ByteBuddyMojo.Coordinate, String> coordinates) Applies this mojo for the given setup.voidexecute()private static StringfindJavaVersionString(org.apache.maven.project.MavenProject project, String property) Makes a best effort of locating the configured Java version.resolveClassPathElements(Map<ByteBuddyMojo.Coordinate, String> coordinates) Resolves the class path elements of the relevant output directory.protected Plugin.Engine.Summarytransform(List<? extends String> classPath, Map<ByteBuddyMojo.Coordinate, String> coordinates, List<ByteBuddyMojo.Transformer> transformers, Plugin.Engine.Source source, Plugin.Engine.Target target, File file, boolean filtered) Applies the instrumentation.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
JAVA_FILE_EXTENSION
-
project
@UnknownNull @Parameter(defaultValue="${project}", readonly=true) public org.apache.maven.project.MavenProject projectThe Maven project. -
execution
@UnknownNull @Parameter(defaultValue="${mojoExecution}", readonly=true) public org.apache.maven.plugin.MojoExecution executionThe current execution of this plugin. -
repositorySystem
The currently used repository system. -
repositorySystemSession
@MaybeNull @Parameter(defaultValue="${repositorySystemSession}", readonly=true) public org.eclipse.aether.RepositorySystemSession repositorySystemSessionThe currently used system session for the repository system. -
transformations
The list of transformations. A transformation must specify the
pluginproperty, containing the name of a class to apply. Additionally, it is possible to optionally specify Maven coordinates for a project that contains this plugin class asgroupId,artifactIdandversion. If any of the latter properties is not set, this projects coordinate is used.For example, the following configuration applies the
foo.Barclass which must implementPluginfrom artifacttransform-artifactwith this project's group and version:<transformations> <transformation> <plugin>foo.Bar< /plugin> <artifactId>transform-artifact< /artifactId> < /transformation> < /transformations>If the list of
transformationsis empty or is not supplied at all, this plugin does not apply but prints a warning. -
initialization
The initializer used for creating a
ByteBuddyinstance and for applying a transformation. By default, a type is rebased. The initializer'sentryPointproperty can be set to any constant name ofEntryPoint.Defaultor to a class name. If the latter applies, it is possible to set Maven coordinates for a Maven plugin which defines this class where any property defaults to this project's coordinates.For example, the following configuration applies the
foo.Quxclass which must implementEntryPointfrom artifactinitialization-artifactwith this project's group and version:<initialization> <entryPoint>foo.Qux< /entryPoint> <artifactId>initialization-artifact< /artifactId> < /initialization> -
suffix
Specifies the method name suffix that is used when type's method need to be rebased. If this property is not set or is empty, a random suffix will be appended to any rebased method. If this property is set, the supplied value is appended to the original method name. -
failOnLiveInitializer
@Parameter(defaultValue="true", required=true) public boolean failOnLiveInitializerWhen transforming classes during build time, it is not possible to apply any transformations which require a class in its loaded state. Such transformations might imply setting a type's static field to a user interceptor or similar transformations. If this property is set tofalse, this plugin does not throw an exception if such a live initializer is defined during a transformation process. -
skip
@Parameter(defaultValue="false", required=true) public boolean skipWhen set totrue, this mojo is not applied to the current module. -
warnOnMissingOutputDirectory
@Parameter(defaultValue="true", required=true) public boolean warnOnMissingOutputDirectoryWhen set totrue, this mojo warns of an non-existent output directory. -
warnOnEmptyTypeSet
@Parameter(defaultValue="true", required=true) public boolean warnOnEmptyTypeSetWhen set totrue, this mojo warns of not having transformed any types. -
failFast
@Parameter(defaultValue="true", required=true) public boolean failFastWhen set totrue, this mojo fails immediately if a plugin cannot be applied. -
extendedParsing
@Parameter(defaultValue="false", required=true) public boolean extendedParsingWhen set totrue, the debug information of class files should be parsed to extract parameter names. -
discovery
Determines if the build should discover Byte Buddy build plugins on this Maven plugin's class loader. Discovered plugins are stored by their name in the /META-INF/net.bytebuddy/build.plugins file where each line contains the fully qualified class name. Discovered plugins are not provided with any explicit constructor arguments. -
classPathDiscovery
@Parameter(defaultValue="false", required=true) public boolean classPathDiscoveryScans the class path (or test class path) for Byte Buddy plugins to apply. This is not normally recommended as it might cause a spurious application of plugins that are accidentally configured on the class path. It can however serve as a convenience in projects with few dependencies where this allows for the use of Maven's dependency version management. -
threads
@Parameter(defaultValue="0", required=true) public int threadsIndicates the amount of threads used for parallel type processing or0for serial processing. -
staleMilliseconds
@Parameter(defaultValue="0", required=true) public int staleMillisecondsDetermines the tolerance of many milliseconds between this plugin run and the last edit are permitted for considering a file as stale if the plugin was executed before. Can be set to-1to disable. -
multiReleaseVersion
Defines the version to use for resolving multi-release jar files. If not set, the Java compile version is used.
-
-
Constructor Details
-
ByteBuddyMojo
public ByteBuddyMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
resolveClassPathElements
protected abstract List<String> resolveClassPathElements(Map<ByteBuddyMojo.Coordinate, String> coordinates) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException Resolves the class path elements of the relevant output directory.- Parameters:
coordinates- Versions for managed dependencies.- Returns:
- The class path elements of the relevant output directory.
- Throws:
org.apache.maven.plugin.MojoExecutionException- If the user configuration results in an error.org.apache.maven.plugin.MojoFailureException- If the plugin application raises an error.
-
apply
protected abstract void apply(List<ByteBuddyMojo.Transformer> transformers, List<String> elements, Map<ByteBuddyMojo.Coordinate, String> coordinates) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException, IOException Applies this mojo for the given setup.- Parameters:
transformers- The transformers to apply.elements- The class path elements to consider.coordinates- Versions for managed dependencies.- Throws:
org.apache.maven.plugin.MojoExecutionException- If the plugin fails due to a user error.org.apache.maven.plugin.MojoFailureException- If the plugin fails due to an application error.IOException- If an I/O exception occurs.
-
transform
protected Plugin.Engine.Summary transform(List<? extends String> classPath, Map<ByteBuddyMojo.Coordinate, String> coordinates, List<ByteBuddyMojo.Transformer> transformers, Plugin.Engine.Source source, Plugin.Engine.Target target, File file, boolean filtered) throws org.apache.maven.plugin.MojoExecutionException, IOException Applies the instrumentation.- Parameters:
classPath- An iterable over all class path elements.coordinates- Versions for managed dependencies.transformers- The transformers to apply.source- The source for the plugin engine's application.target- The target for the plugin engine's application.file- The file representing the source location.filtered-trueif files are already filtered and should not be checked for staleness.- Returns:
- A summary of the applied transformation.
- Throws:
org.apache.maven.plugin.MojoExecutionException- If the plugin cannot be applied.IOException- If an I/O exception occurs.
-
findJavaVersionString
@MaybeNull private static String findJavaVersionString(org.apache.maven.project.MavenProject project, String property) Makes a best effort of locating the configured Java version.- Parameters:
project- The relevant Maven project.property- The targeted Maven property.- Returns:
- The Java version string of the configured build Java version or
nullif no explicit configuration was detected.
-