https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Andrew

11/15/2020, 3:56 AM
If you omit the full package names in a KMP project is there a way to have the java code built with prefixing the full package. For example if you used "package mypackage" can the java code be built as if you used "package com.example.mypackage"?
g

gildor

11/15/2020, 6:12 AM
No, I don't think it's possible, it would create a lot of edge cases. What is your use case for it?
a

Andrew

11/15/2020, 6:18 AM
Minor issue is to not have the warning "Package directive doesn't match the file location" because kotlin doesn't require the full path /com/example/mypackage but more importantly when using kotlin JS to have a more simplified naming structure since it requires the fully qualified name to access any class. Java needs full package name but JS is better without it.
g

gildor

11/15/2020, 6:22 AM
Java doesn't need full package, it's not a requirement, you can use mypackage as package name with no problems
Warning about package doesn't match is purely IDE inspection, and even more, you can disable it and there is even an option to specify package prefix for ide, so ide will not complain that you do not follow full package structure (it's even recommended for Kotlin projects)
l

louiscad

11/15/2020, 11:21 AM
@gildor How to specify the package prefix for the IDE? I am not finding it on the page you linked.
l

louiscad

11/28/2020, 1:17 AM
I was about to use it, and I realized that there's no longer any warning regarding package mismatch if the path after
src/main/kotlin
is contained in the end of the package directive. Happy about it, because the idea-ext Gradle Plugin expected Groovy consumers and I didn't like the boilerplate it was leaving in the Kotlin DSL build files.
g

gildor

11/28/2020, 2:41 AM
It's not only about warning, this setting also needed for some IDE actions such as create new files in the package or move files, otherwise it would create dirs for your root project Though it also can be just set to idea settings (which also can be shared)
l

louiscad

11/28/2020, 11:23 AM
Ah yes, I notices moving files was not nice… I think I'll make a buildSrc function to hide the boilerplate
I tried it, but move is still broken. Did you get it working with Gradle Kotlin DSL in Android Studio 4.2 Canary 16 ?
g

gildor

11/29/2020, 12:19 AM
I use only standard maven layouts everywhere, tried non standard only once, getting rid of a few folders doesn't worth all those issues with non-standard configs and strange ide behavior
¯\_(ツ)_/¯
l

louiscad

11/29/2020, 9:11 AM
I hope @elizarov words will lead to action landing in Kotlin 1.5: https://twitter.com/relizarov/status/1305414701552209921?s=19 It seems there's already groundwork as the behavior of the package directive warning infers the base package, and triggers warnings if there's any inconsistency, but fades back away if the root package is consistent with all the files in the hierarchy. IDE refactorings is the only missing part I think.
I'm wondering if there's an open issue about this
2 Views