sbt-byte-buddy - compile-time code generation via ByteBuddy in sbt
Install the plugin by adding the following to
addSbtPlugin("net.bytebuddy" % "sbt-byte-buddy" % "1.2.0")
And then modify your
build.sbt to enable the SbtByteBuddy plugin:
lazy val myProject = (project in file(".")) .enablePlugins(ByteBuddyPlugin)
If you want to disable the ByteBuddy plugin, use the
byteBuddyEnabled := false
byteBuddyPlugins is the list of transformations. A transformation must specify the ByteBuddy plugin (implementing net.bytebuddy.build.Plugin), containing the name of a class or classes to apply.
byteBuddyPlugins := Seq("com.package.SomeByteBuddyPlugin")
byteBuddyInitialization setting defines the initializer used for creating a ByteBuddy instance and for applying a transformation. By default, a type is rebased. The setting can be set to any constant name of
EntryPoint.Default or to a class name (extending net.bytebuddy.build.EntryPoint).
byteBuddyInitialization := "com.package.SomeEntryPoint"
byteBuddySuffix specifies the method name suffix that is used when type's method need to be rebased. If this setting is not set or is empty, a random suffix will be appended to any rebased method. If this setting is set, the supplied value is appended to the original method name.
byteBuddySuffix := "SomeSufffix"
byteBuddyPackages is an optional setting to set the filter to search for classes to transform.
It can be used to select all classes under the package:
byteBuddyPackages := Seq("com.sompackage.*")
Or to select a single class:
byteBuddyPackages := Seq("com.package.SomeClass")
Since the transformation plugins may be only used during the compile-only, there is no need to include the dependencies for the transformation plugins during runtime.
// a 'compile-only' configuation ivyConfigurations += config("compile-only").hide // some compileonly dependency libraryDependencies += "commons-io" % "commons-io" % "2.4" % "compile-only" // appending everything from 'compileonly' to unmanagedClasspath unmanagedClasspath in Compile ++= update.value.select(configurationFilter("compile-only"))
That dependency will not appear in the
pom.xml generated by publish and friends.
This project is released under terms of the Apache 2.0.