Hey everyone. Maybe someone could give a little he...
# gradle
c
Hey everyone. Maybe someone could give a little help. What is the right way to use
DomainObjectCollection.withType
in Kotlin DSL? my example when writing a Plugin :
Copy code
project.run {
    repositories.withType(MavenArtifactRepository::class.java) {
        // I want to access the typed repo
        dostuff( this)
    }
}
what Building gives me: Error:(22, 44) Kotlin: Type mismatch: inferred type is Project but MavenArtifactRepository was expected I tried
this@withType
but that just yields: ‘this’ is not defined in this context. Can anyone hint me how to do this?
c
try like this:
Copy code
project.run {
	repositories.withType<MavenArtifactRepository> {
		doStuffTo(this)
	}
}
with kotlin try to avoid using
::class.java
when a reified generic is available, like in this instance. Generic looks far cleaner and gives you type inference.
c
Argh. Haven’t noticed this. 😖 Thank you! 🙂
😉 1