Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are there folders named "kotlin" instead of "java" #31

Closed
vmadalin opened this issue Oct 28, 2020 · 1 comment
Closed

Why are there folders named "kotlin" instead of "java" #31

vmadalin opened this issue Oct 28, 2020 · 1 comment
Labels
question Further information is requested

Comments

@vmadalin
Copy link
Owner

vmadalin commented Oct 28, 2020

I'm curious about your project structure. Why are there folders named "kotlin" instead of "java"? Like app/src/main/kotlin/com.xx. I can't create a project like this using AS.

Originally posted by @oOJohn6Oo in #20 (comment)

@vmadalin
Copy link
Owner Author

First of all thanks @oOJohn6Oo for your question. I added as a new issue just to give it more visibility to other people that are interesting in this answer.

Definitely, Android Studio by default it creates new classes under "java" directory following the same path with .java files. But because I using .kt files there is no reason to still keeping naming the same directory with java. Of course, there are no best practices or convention on that. It's just a personal criteria for aligning naming. For me is like you have a box with "apples" but you put tag as "pears".

Hopefully, the AS gonna support this in the future like Kotlin DSL but for the moment you need to do it manually by adding on the gradle:

sourceSets {
        getByName("main") {
            java.srcDir("src/main/kotlin")
        }
        getByName("test") {
            java.srcDir("src/test/kotlin")
        }
        getByName("androidTest") {
            java.srcDir("src/androidTest/kotlin")
        }
    }

Of course, if you create a common gradle for the features, kotlin-library, android-library you don't need to add them on each new module, just apply the plugin by:

plugins {
    id("commons.android-library")
}

@vmadalin vmadalin added the question Further information is requested label Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant