# ObjectFactory

@ServiceScope(value = [Global::class, BuildTree::class, Project::class])
interface ObjectFactory(source)

A factory for creating various kinds of model objects.

An instance of the factory can be injected into a task, plugin or other object by annotating a public constructor or property getter method with `javax.inject.Inject`. It is also available via getObjects.

#### Since

4.0

## Functions

directoryProperty
Link copied to clipboard
abstract fun directoryProperty(): DirectoryProperty
Creates a new DirectoryProperty that uses the project directory to resolve relative paths, if required.
domainObjectContainer
Link copied to clipboard
abstract fun <T> domainObjectContainer(elementType: Class<T>): NamedDomainObjectContainer<T>
abstract fun <T> domainObjectContainer(elementType: Class<T>, factory: NamedDomainObjectFactory<T>): NamedDomainObjectContainer<T>
Creates a new NamedDomainObjectContainer for managing named objects of the specified type.
domainObjectSet
Link copied to clipboard
abstract fun <T> domainObjectSet(elementType: Class<T>): DomainObjectSet<T>
Creates a new DomainObjectSet for managing objects of the specified type.
fileCollection
Link copied to clipboard
abstract fun fileCollection(): ConfigurableFileCollection
Creates a new ConfigurableFileCollection.
fileProperty
Link copied to clipboard
abstract fun fileProperty(): RegularFileProperty
Creates a new RegularFileProperty that uses the project directory to resolve relative paths, if required.
fileTree
Link copied to clipboard
abstract fun fileTree(): ConfigurableFileTree
Creates a new ConfigurableFileTree.
listProperty
Link copied to clipboard
abstract fun <T> listProperty(elementType: Class<T>): ListProperty<T>
Creates a ListProperty implementation to hold a List of the given element type `T`.
mapProperty
Link copied to clipboard
abstract fun <K, V> mapProperty(keyType: Class<K>, valueType: Class<V>): MapProperty<K, V>
Creates a MapProperty implementation to hold a Map of the given key type `K` and value type `V`.
named
Link copied to clipboard
abstract fun <T : Named?> named(type: Class<T>, name: String): T
Creates a simple immutable Named object of the given type and name.
namedDomainObjectList
Link copied to clipboard
abstract fun <T> namedDomainObjectList(elementType: Class<T>): NamedDomainObjectList<T>
Creates a new NamedDomainObjectList for managing named objects of the specified type.
namedDomainObjectSet
Link copied to clipboard
abstract fun <T> namedDomainObjectSet(elementType: Class<T>): NamedDomainObjectSet<T>
Creates a new NamedDomainObjectSet for managing named objects of the specified type.
newInstance
Link copied to clipboard
abstract fun <T> newInstance(type: Class<out T>, parameters: Array<Any>): T
Create a new instance of T, using `parameters` as the construction parameters.
polymorphicDomainObjectContainer
Link copied to clipboard
abstract fun <T> polymorphicDomainObjectContainer(elementType: Class<T>): ExtensiblePolymorphicDomainObjectContainer<T>
Creates a new ExtensiblePolymorphicDomainObjectContainer for managing named objects of the specified type.
property
Link copied to clipboard
abstract fun <T> property(valueType: Class<T>): Property<T>
Creates a Property implementation to hold values of the given type.
setProperty
Link copied to clipboard
abstract fun <T> setProperty(elementType: Class<T>): SetProperty<T>
Creates a SetProperty implementation to hold a Set of the given element type `T`.
sourceDirectorySet
Link copied to clipboard
abstract fun sourceDirectorySet(name: String, displayName: String): SourceDirectorySet
Creates a SourceDirectorySet.