Class ByteboxExtension

java.lang.Object
dev.gmitch215.bytebox.gradle.ByteboxExtension

public abstract class ByteboxExtension extends Object
The bytebox { } block.
 bytebox {
 	handlerClass = "com.example.MyWorker"

 	size {
 		module = ModuleType.AUTO
 		budget = "250KiB"
 	}

 	wrangler {
 		name = "my-worker"
 		compatibilityDate = "2026-08-22"
 		routes("example.com/*")
 		crons("*/5 * * * *")
 	}

 	bindings {
 		kv()
 		d1()
 	}
 }
Since:
1.0.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    ByteboxExtension(org.gradle.api.model.ObjectFactory objects)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Declares bindings by type, each taking its default name.
    void
    bindings(org.gradle.api.Action<Bindings> action)
    Declares bindings.
    void
    durableObjects(String... classes)
    Exposes Java classes as Durable Objects.
    Returns the declared bindings.
    abstract org.gradle.api.provider.Property<Boolean>
    Returns whether applying the plugin puts bytebox on the classpath, which it does by default.
    abstract org.gradle.api.provider.Property<String>
    Returns the version of bytebox-core to add, defaulting to the plugin's own.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the Java classes to expose as Durable Objects, fully qualified.
    abstract org.gradle.api.provider.Property<String>
    Returns the class implementing one or more of the trigger interfaces.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the types to generate JSON codecs for, fully qualified.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the npm packages to generate Java bindings for.
    abstract org.gradle.api.provider.Property<Boolean>
    Returns whether the generator may import a package to read exports no static analysis can see.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the npm packages the compiled program imports, as name@range.
    abstract org.gradle.api.provider.Property<String>
    Returns which runtime runs the Wrangler CLI.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the types to generate java.io serialization codecs for, fully qualified.
    Returns how the compiled module is packed and how big it is allowed to get.
    Returns what goes into the generated Wrangler configuration.
    void
    jsonTypes(String... types)
    Adds types to generate JSON codecs for.
    void
    npm(String name, String version)
    Declares an npm package the compiled program imports.
    void
    npmBindings(String... packages)
    Asks for generated Java bindings for packages already declared with npm(java.lang.String, java.lang.String).
    void
    serialTypes(String... types)
    Adds types to generate serialization codecs for.
    void
    size(org.gradle.api.Action<SizeSpec> action)
    Configures packing and the size budget.
    void
    wrangler(org.gradle.api.Action<WranglerSpec> action)
    Configures the generated Wrangler configuration.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteboxExtension

      @Inject public ByteboxExtension(org.gradle.api.model.ObjectFactory objects)
      Parameters:
      objects - Gradle's factory, for the nested blocks
  • Method Details

    • getHandlerClass

      public abstract org.gradle.api.provider.Property<String> getHandlerClass()
      Returns the class implementing one or more of the trigger interfaces.

      Which interfaces it implements decides which handlers the generated Worker exports and which trigger keys the generated Wrangler configuration carries. An unimplemented trigger produces neither.

      Returns:
      the class implementing one or more of the trigger interfaces
    • getCoreDependency

      public abstract org.gradle.api.provider.Property<Boolean> getCoreDependency()
      Returns whether applying the plugin puts bytebox on the classpath, which it does by default.

      Set this false for a project that resolves bytebox some other way: a composite build, a local jar, or a version catalog entry it would rather own.

      Returns:
      whether applying the plugin puts bytebox on the classpath, which it does by default
    • getCoreVersion

      public abstract org.gradle.api.provider.Property<String> getCoreVersion()
      Returns the version of bytebox-core to add, defaulting to the plugin's own.

      The two are released together, so the default is the pair that was tested. A project that pins something else is choosing to compile against a surface these generators may not write.

      Returns:
      the version of bytebox-core to add, defaulting to the plugin's own
    • getRunner

      public abstract org.gradle.api.provider.Property<String> getRunner()
      Returns which runtime runs the Wrangler CLI.

      Resolved once, in this order: a wrangler already on PATH, then bunx, then deno, then npx. Set this to pin one.

      Returns:
      which runtime runs the Wrangler CLI
    • getJSONTypes

      public abstract org.gradle.api.provider.ListProperty<String> getJSONTypes()
      Returns the types to generate JSON codecs for, fully qualified.

      Only needed for a type the annotation cannot reach: one in a dependency, or one whose source you do not control. Anything annotated @JSONType in this project is found on its own.

      Returns:
      the types to generate JSON codecs for, fully qualified
    • jsonTypes

      public void jsonTypes(String... types)
      Adds types to generate JSON codecs for.
      Parameters:
      types - the fully qualified type names
    • getDurableObjectClasses

      public abstract org.gradle.api.provider.ListProperty<String> getDurableObjectClasses()
      Returns the Java classes to expose as Durable Objects, fully qualified.

      Which handlers each one gets is read from the interfaces it implements, so an object that takes no alarm has no alarm handler in the generated JavaScript class.

      Returns:
      the Java classes to expose as Durable Objects, fully qualified
    • durableObjects

      public void durableObjects(String... classes)
      Exposes Java classes as Durable Objects.

      The build writes the JavaScript class the runtime instantiates, the binding, and the migration that creates the class. One Java instance exists per Durable Object instance, so a field on it is that object's memory.

       bytebox {
       	durableObjects("com.example.Counter", "com.example.Room")
       }
      
      Parameters:
      classes - the fully qualified class names
    • getSerialTypes

      public abstract org.gradle.api.provider.ListProperty<String> getSerialTypes()
      Returns the types to generate java.io serialization codecs for, fully qualified.

      Only needed for a type the annotation cannot reach. Anything annotated @SerialType in this project is found on its own.

      Returns:
      the types to generate java.io serialization codecs for, fully qualified
    • serialTypes

      public void serialTypes(String... types)
      Adds types to generate serialization codecs for.
      Parameters:
      types - the fully qualified type names
    • getNPMPackages

      public abstract org.gradle.api.provider.ListProperty<String> getNPMPackages()
      Returns the npm packages the compiled program imports, as name@range.

      An npm package is JavaScript, so it never enters the WebAssembly. It stays on the JavaScript side and costs bundle bytes rather than module bytes.

      Returns:
      the npm packages the compiled program imports, as name@range
    • npm

      public void npm(String name, String version)
      Declares an npm package the compiled program imports.

      Writes it into the generated package.json and emits a static import beside the loader, which is what makes it resolvable: a package name reached only from inside the WebAssembly lives in a custom section, and no bundler can follow that.

      Reach it from Java with @JSBodyImport:

       @JSBody(
       	params = "size",
       	imports = @JSBodyImport(alias = "nanoid", fromModule = "nanoid"),
       	script = "return nanoid.nanoid(size);"
       )
       private static native String id(int size);
      
      Parameters:
      name - the package name
      version - the version range
    • getNPMBindingPackages

      public abstract org.gradle.api.provider.ListProperty<String> getNPMBindingPackages()
      Returns the npm packages to generate Java bindings for.

      A subset of getNPMPackages(), because generating needs the package installed and a JavaScript runtime on PATH while merely depending on one does not.

      Returns:
      the npm packages to generate Java bindings for
    • npmBindings

      public void npmBindings(String... packages)
      Asks for generated Java bindings for packages already declared with npm(java.lang.String, java.lang.String).

      generateNpmBindings reads each package's TypeScript types and writes a class of @JSBody methods onto the main source set, so the package is callable without a line of hand-written interop. A subpath export is named the way an import names it:

       bytebox {
       	npm("nanoid", "^5.0.9")
       	npmBindings("nanoid", "edgeport/smtp")
       }
      

      What a package's types cannot express becomes TSObject, and the task prints which tier each package resolved on, so a thin binding is visible rather than a surprise.

      Parameters:
      packages - the package specifiers
    • getNPMIntrospection

      public abstract org.gradle.api.provider.Property<Boolean> getNPMIntrospection()
      Returns whether the generator may import a package to read exports no static analysis can see.

      On by default. Installing a package already runs its own install scripts, so importing one is not a new trust boundary — but it is the only tier that executes third-party code, and this is how a build says it may not.

      Returns:
      whether the generator may import a package to read exports no static analysis can see
    • getSize

      public SizeSpec getSize()
      Returns how the compiled module is packed and how big it is allowed to get.
      Returns:
      how the compiled module is packed and how big it is allowed to get
    • size

      public void size(org.gradle.api.Action<SizeSpec> action)
      Configures packing and the size budget.
      Parameters:
      action - the configuration
    • getWrangler

      public WranglerSpec getWrangler()
      Returns what goes into the generated Wrangler configuration.
      Returns:
      what goes into the generated Wrangler configuration
    • wrangler

      public void wrangler(org.gradle.api.Action<WranglerSpec> action)
      Configures the generated Wrangler configuration.
      Parameters:
      action - the configuration
    • getBindings

      public Bindings getBindings()
      Returns the declared bindings.
      Returns:
      the declared bindings
    • bindings

      public void bindings(org.gradle.api.Action<Bindings> action)
      Declares bindings.
      Parameters:
      action - the configuration
    • bindings

      public void bindings(BindingType... types)
      Declares bindings by type, each taking its default name.
      Parameters:
      types - the types