Class UberJarGenerator
- All Implemented Interfaces:
Generator, ResourceProvider, ResourceRetriever
A Generator for uber jars.
Depending on the request, the generator provides two types of resources.
-
A
JarFile. This type of resource is also returned if a more generalResourceTypesuch asClasspathElementis requested. -
An
AppJarFile. When requesting this special jar type, the generator checks if a main class is specified.
The generator takes the following approach:
- Request all
ClasspathElements from the providers. Add the resource trees and the jar files to the sources to be processed. Ignore jar files from maven repositories (instances ofMvnRepoJarFile). - Request all
MvnRepoResources from the providers and use them for a dependency resolution. Add the jar files from the dependency resolution to the resources to be processed. - Add resources from the sources to the uber jar. Merge the files in
META-INF/services/that have the same name by concatenating them. - Filter out any other duplicate direct child files of
META-INF. These files often contain information related to the origin jar that is not applicable to the uber jar. - Filter out any module-info.class entries.
Note that the resource type of the uber jar generator's output is one
of the resource types of its inputs, because uber jars can also be used
as ClasspathElement. Therefore, if you want to create an uber jar
from all resources provided by a project, you must not add the
generator to the project like this:
generator(UberJarGenerator::new).add(this); // Circular dependency
This would add the project as provider and thus make the uber jar generator as supplier to the project its own provider (via Project.provide). Rather, you have to use this slightly more complicated approach to adding providers to the uber jar generator:
generator(UberJarGenerator::new)
.addAll(providers(EnumSet.of(Forward, Expose, Supply)));
This requests the same providers from the project as
Project.provide does, but allows the uber jar
generator's LibraryGenerator.from(org.jdrupes.builder.api.ResourceProvider...) method to filter out the uber jar
generator itself from the providers. The given intends can
vary depending on the requirements.
If you don't want the generated uber jar to be available to other generators of your project, you can also add it to a project like this:
dependency(new UberJarGenerator(this)
.from(providers(EnumSet.of(Forward, Expose, Supply))), Intend.Forward)
Of course, the easiest thing to do is separate the generation of class trees or library jars from the generation of the uber jar by generating the uber jar in a project of its own. Often the root project can be used for this purpose.
-
Field Summary
Fields inherited from class AbstractProvider
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcollectFromProviders(Map<Path, Resources<IOResource>> contents) Collects the contents from the providers.doProvide(ResourceRequest<T> requested) Invoked byAbstractProvider.provide(ResourceRequest)after checking if the invocation is allowed.protected voidresolveDuplicates(Map<Path, Resources<IOResource>> entries) Resolve duplicates.Methods inherited from class LibraryGenerator
collectContents, from, from, mainClass, mainClass, providersMethods inherited from class JarGenerator
add, add, addEntries, addTrees, attributes, attributes, buildJar, collect, destination, destination, destination, jarName, jarName, jarNameMethods inherited from class AbstractGenerator
cleanup, name, name, newResource, project, toStringMethods inherited from class AbstractProvider
provideMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
provide
-
Constructor Details
-
UberJarGenerator
Instantiates a new uber jar generator.- Parameters:
project- the project
-
-
Method Details
-
collectFromProviders
Description copied from class:LibraryGeneratorCollects the contents from the providers. This implementation requestsClassTrees andJavaResourceTrees.- Overrides:
collectFromProvidersin classLibraryGenerator- Parameters:
contents- the contents
-
resolveDuplicates
Description copied from class:JarGeneratorResolve duplicates. The default implementation outputs a warning and skips the duplicate entry.- Overrides:
resolveDuplicatesin classJarGenerator- Parameters:
entries- the entries
-
doProvide
Description copied from class:AbstractProviderInvoked byAbstractProvider.provide(ResourceRequest)after checking if the invocation is allowed.- Overrides:
doProvidein classLibraryGenerator- Type Parameters:
T- the generic type- Parameters:
requested- the requested- Returns:
- the stream
-