# SourceDirectories

# SourceDirectories

<br />

```
@Incubating interface SourceDirectories
```

<br />

*** ** * ** ***

Represents all the source folders for a source type in the variant.

since 7.2

## Summary

|                                                                                                                                                                                                                                                                                                                                                                  ### Public functions                                                                                                                                                                                                                                                                                                                                                                  ||
|------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | `<T : `[Task](https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html)`?> `[add](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#add(org.gradle.api.tasks.TaskProvider,kotlin.Function1))`(taskProvider: `[TaskProvider](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html)`<T?>?, wiredWith: ((T) `->` `[Provider](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)`<`[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)`>)?)` Add the output of a custom task to the list of source directories. |
| [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [addSrcDir](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#addSrcDir(kotlin.String))`(srcDir: `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?)` Add a source directory with sources already present to the variant.                                                                                                                                                                                                                                                                                                                                                    |

|                                                                                                                                                                                                                                                                                                              ### Public properties                                                                                                                                                                                                                                                                                                               ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Provider](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)`<`[List](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)`<`[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)`>>` | [all](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#all()) Get all registered source folders and files as a[List](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)of[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html). |

|                                                                                                                                                                                                                   ### Inherited functions                                                                                                                                                                                                                   ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| From class[Named](https://docs.gradle.org/current/javadoc/org/gradle/api/Named.html) |----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html) | [getName](https://docs.gradle.org/current/javadoc/org/gradle/api/Named.html#getName--)`()` | |

## Public functions

### add

```
fun <T : Task?> add(taskProvider: TaskProvider<T?>?, wiredWith: ((T) -> Provider<Directory>)?): Unit
```

Add the output of a custom task to the list of source directories.

The[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)is the output of a Task[T](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#add(org.gradle.api.tasks.TaskProvider,kotlin.Function1))that has been registered using the Gradle's Task manager.

The[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)is added last to the variant's list of source directories. In case there is merging for the source type, the[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)will have the highest priority.  

|                                                                                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                                                                                ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `taskProvider: `[TaskProvider](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html)`<T?>?`                                                                                           | the[TaskProvider](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/TaskProvider.html)returned by Gradle's Task manager when registering the Task of type[T](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#add(org.gradle.api.tasks.TaskProvider,kotlin.Function1)).          |
| `wiredWith: ((T) `->` `[Provider](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)`<`[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html)`>)?` | the method reference returning the[T](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#add(org.gradle.api.tasks.TaskProvider,kotlin.Function1))task's output to use as a source directory. The generated source directory location is automatically determined by the Android Gradle Plugin |

### addSrcDir

```
fun addSrcDir(srcDir: String?): Unit
```

Add a source directory with sources already present to the variant.

The directory will be added last in the list of source folders for the variant. In case there is merging for the source type,[srcDir](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#addSrcDir(kotlin.String))will be the folder with the highest priority.

Do not use[addSrcDir](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#addSrcDir(kotlin.String))to add sources that are generated by a task, instead use[add](https://developer.android.com/reference/tools/gradle-api/7.2/com/android/build/api/variant/SourceDirectories#add(org.gradle.api.tasks.TaskProvider,kotlin.Function1))  

|                                                                                                                                                      Parameters                                                                                                                                                      ||
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `srcDir: `[String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html)`?` | the source directory path, that will be resolved using the[Directory.dir](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html#dir-kotlin.String-)API relative to the Gradle project directory. |

## Public properties

### all

```
val all: Provider<List<Directory>>
```

Get all registered source folders and files as a[List](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html)of[Directory](https://docs.gradle.org/current/javadoc/org/gradle/api/file/Directory.html).

Some source types do not have the concept of overriding, while others require a merging step to ensure only one source file is used when processing begins.

The returned[Provider](https://docs.gradle.org/current/javadoc/org/gradle/api/provider/Provider.html)can be used directly in a[org.gradle.api.tasks.InputFiles](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/InputFiles.html)annotated property of a[Task](https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html)