Class LibraryBuilder

All Implemented Interfaces:
Generator, Renamable, ResourceProvider, ResourceRetriever
Direct Known Subclasses:
UberJarBuilder

public class LibraryBuilder extends JarBuilder implements ResourceRetriever

A Generator for Java libraries packaged as jars. A library jar is expected to contain class files and supporting resources together with additional information in META-INF/.

The generator provides two types of resources.

  1. A LibraryJarFile. This type of resource is also returned if a more general ResourceType such as CodeContribution is requested.

  2. An AppJarFile. When requesting this special jar type, the generator checks if a main class is specified.

In addition to explicitly adding resources, this generator supports resource retrieval from added providers. The resources of type ClassTree and JavaResourceTree that the providers added with ResourceRetriever.addFrom(ResourceProvider...) supply are included in the library in addition to the explicitly added resources.

The enables the simple standard pattern for creating a library:

generator(LibraryBuilder::new).addFrom(this);

JPMS support

When the compiled classes contain a module-info.class, the JAR is a named module. If no module-info.class is present but moduleName is set (or auto-detected from the project name), an Automatic-Module-Name manifest attribute is added so the JAR is treated as an automatic module on the module-path.