Anyone know how to do this in an Android project w...
# gradle
z
Anyone know how to do this in an Android project with the Kotlin DSL?
Copy code
sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
    }
c
Copy code
sourceSets {
	main { java.srcDirs("src/main/kotlin") }
	test { java.srcDirs("src/test/kotlin") }
}
I also sometimes use more verbose approach which is more understandable when read by people who don't know gradle API very well:
Copy code
sourceSets {
	main { java.srcDirs.add(file("src/main/kotlin")) }
	test { java.srcDirs.add(file("src/test/kotlin")) }
}
Note, this will only work if you're using
plugins {}
approach to applying plugins
z
I am using plugins block but it doesn’t seem to be working. Do I need to import anything?
Also I’m not using gradle 5 because I was under the impression that it doesn’t work with Android. I’m using 4.10.3
Acutally… of course I don’t need to import anything, I wasn’t thinking clearly.
But not sure what I’m doing wrong here, it’s just saying main and test don’t exist.
s
Inside app/build.gradle.kts
Copy code
android {
...
    sourceSets {
        getByName("main").java.srcDirs("src/main/kotlin")
    }
}
z
That’s working, thanks!