Problem with transforming deprecated TransformAPI to DefaultTask


I’m currently working on transforming code from deprecated TransformAPI to equivalent DefaultTask.

Code is used for filtering files during build time.
Here is a part of the TransformAPI code:

class CustomTransform(private val regularExpressionList: List<String>) : Transform() {

    override fun getName(): String {
        return "Custom"

    override fun getInputTypes(): MutableSet<QualifiedContent.ContentType> {
        return Collections.singleton(QualifiedContent.DefaultContentType.CLASSES)

    override fun getScopes(): MutableSet<in QualifiedContent.Scope> {
        return EnumSet.of(QualifiedContent.Scope.PROJECT)

    override fun isIncremental(): Boolean {
        return false

    @Throws(TransformException::class, InterruptedException::class, IOException::class)
    override fun transform(transformInvocation: TransformInvocation) {
        val patternList = generatePatterns(regularExpressionList)
        transformInvocation.inputs.forEach { input ->
            input.directoryInputs.forEach { dirInput ->
                val output = transformInvocation.outputProvider.getContentLocation(
                val pathBitLength = dirInput.file.toString().length
                dirInput.file.walk().forEach { file ->
                    val path = file.toString().substring(pathBitLength)
                    if (file.isDirectory) {
                        File(output, path).mkdirs()
                    } else {
                        if (!matchesRegularExpressions(path, patternList)) {
                            File(output, path).writeBytes(file.readBytes())
                        } else {

    private fun generatePatterns(regularExpressionList: List<String>): List<Pattern> {
        val patternList = ArrayList<Pattern>(regularExpressionList.size)

        for (regularExpression in regularExpressionList) {
            patternList.add(Pattern.compile(regularExpression, Pattern.CASE_INSENSITIVE))

        return patternList

    private fun matchesRegularExpressions(word: String, patternList: List<Pattern>): Boolean {
        for (pattern in patternList) {
            val matcher = pattern.matcher(word)
            if (matcher.find()) return true
        return false

I’m not sure how to achieve similar task with DefaultTask.
What dependsOn should I set on task and how to apply copied files to my build?

What even is Transform or TransformAPI?
Never seen that in Gradle.
I guess this is from some 3rd party Gradle plugin, so maybe you should ask that plugins maintainer or documentation how to replace it if it is deprecated?

If this is for transforming some artifacts, you might want to look into Gradle artifact transforms instead of a task.

When writing a task, you should practically never use any explicit dependsOn but always wire task outputs to task inputs and thus get the necessary task dependencies automatically where necessary.