Skip to content
Edit this page

Dependencies

The cloner needs nothing but the JDK: its POM has no dependencies. Optional libraries and JDK modules switch on faster or wider mechanisms; without them the cloner falls back to others and still clones.

Libraries

Library Needed for Without it
org.ow2.asm:asm:9.11.1 generated copiers and the copy constructors of the agent on JDK 8 to 23 JDK 24+ uses its ClassFile API; older JDKs copy classes by their fields, slower, and the agent adds no copy constructors
io.github.toolfactory:narcissus:1.0.14 Narcissus: Toolsets.narcissus(), opening the packages of the JDK without the agent and without Unsafe the default toolset opens the packages by the agent or Unsafe, see Toolsets
<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>9.11.1</version>
</dependency>
<dependency>
    <groupId>io.github.toolfactory</groupId>
    <artifactId>narcissus</artifactId>
    <version>1.0.14</version>
</dependency>
runtimeOnly("org.ow2.asm:asm:9.11.1")
runtimeOnly("io.github.toolfactory:narcissus:1.0.14")

ASM is used by the agent if it is on the classpath of the cloner or of the class loader of the enhanced classes. Since JDK 24 Narcissus needs --enable-native-access=ALL-UNNAMED, otherwise the JVM warns that it loads a native library.

Build tools

io.github.sugar-cubes:sugar-cubes-cloner-tools (the annotation processor, the Maven plugin and the Gradle plugin) brings ASM itself, nothing else is needed in the build. The project depends on the cloner, as for cloning anyway: the copy constructors call it. Groovy reads the copy constructors of Java superclasses at compilation, so a project with Groovy needs the cloner on the compile classpath (implementation, not runtimeOnly). See Build tools.

Agent

The jar of the cloner is the agent, nothing else is needed: -javaagent:/path/to/sugar-cubes-cloner-2.2.2.jar. On JDK 8 to 23 it adds copy constructors only with ASM, see above. See Agent.

JDK modules

The cloner uses these modules of the JDK if they are present (requires static in its module descriptor):

Module Gives Without it
jdk.unsupported sun.misc.Unsafe and sun.reflect.ReflectionFactory objects are created only by their constructors without arguments, fields are reached by reflection only in packages open to the cloner, the packages of the JDK are opened only by the agent or Narcissus
java.instrument the agent no agent

Every JDK has them. An application on the classpath gets them without any options; in a runtime image built by jlink list them to jlink: --add-modules jdk.unsupported. An application on the module path resolves only the modules it requires, also in an image: requires static of the cloner adds neither jdk.unsupported nor ASM or Narcissus. Require them in your module descriptor:

module com.acme.app {
    requires io.github.sugarcubes.cloner;
    // Unsafe and ReflectionFactory: classes without a constructor without arguments, closed packages
    requires jdk.unsupported;
    // generated copiers on JDK 8 to 23, ASM on the module path
    requires org.objectweb.asm;
}

or start the JVM with --add-modules jdk.unsupported,org.objectweb.asm. jlink adds the required modules to the image by itself. A module which only --add-modules of jlink gives a modular application is in the image but not resolved, unless the launcher of the image adds it too: --add-options=" --add-modules=jdk.unsupported" (the space keeps jlink from reading the value as its own option). -javaagent adds java.instrument by itself.

Without jdk.unsupported the default toolset is Toolset[moduleOpening=NONE, allocation=[], constructorFallback=constructors, fieldAccess=[REFLECTION]], and a class without a constructor without arguments fails with No instance allocator supports ....