Hello i'm trying to migrate gradle to kotlin dsl a...
# gradle
a
Hello i'm trying to migrate gradle to kotlin dsl and i have some blocked point, someone can help me please:
Copy code
allprojects {
    // Add this to remove limit of 100 build error
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xmaxerrs" << "4000"
            options.compilerArgs << "-Xmaxwarns" << "4000"
        }
    }
    afterEvaluate {
        if (project.plugins.hasPlugin("kotlin-kapt")) {
            kapt {
                javacOptions {
                    option("-Xmaxerrs", 10000)
                }
            }
        }
    }
}
t
and what is your problem exactly?
a
I can't see how can i write this in kotlin dsl
t
probably something like this will work:
Copy code
allprojects { subProject ->
    subProject.tasks.withType(JavaCompile::class.java).configureEach {
        it.options.compilerArgs += listOf("-Xmaxerrs", "4000", "-Xmaxwarns", "4000")
    }
    
    subproject.plugins.withId("kotlin-kapt") {
        subProject.extensions.configure(org.jetbrains.kotlin.gradle.plugin.KaptExtension::class.java) {
            it.javacOptions {
                option("-Xmaxerrs", 1000)
            }
        }
    }
}
👀 1
👍 1
v
I would even rewrite the Groovy version. 😄 Why is there he
projectsEvaluated
? And don't use
afterEvaluate
bud use
project.pluginManager.withPlugin
instead. Don't use
withType(type, action)
but
withType(type).configureEach(action)
if you care about task configuration avoidance
👍 1
👀 1
I think this should do:
Copy code
allprojects {
    tasks.withType<JavaCompile>().configureEach {
        options.compilerArgs.addAll(listOf("-Xmaxerrs", "4000", "-Xmaxwarns", "4000"))
    }
    pluginManager.withPlugin("kotlin-kapt") {
        configure<KaptExtension> {
            javacOptions {
                option("-Xmaxerrs", 10000)
            }
        }
    }
}
❤️ 1
👀 1