https://kotlinlang.org logo
Title
p

pniederw

01/18/2019, 12:23 PM
Should Kotlin libraries use Maven scope
provided
for their dependency on kotlin-stdlib?
k

karelpeeters

01/18/2019, 12:28 PM
I'm not that familiar with maven, but looking at https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope:
provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
That doesn't seem to be the right scope, the JDK doesn't provide the stdlib, right? It's just an ordinary dependency.
p

pniederw

01/18/2019, 12:30 PM
I was thinking the Kotlin application provides it, but forgot that it's not a given that the consumer is written in Kotlin.
Hence you are right,
provided
doesn't make sense here.
t

tipsy

01/18/2019, 3:34 PM
let me know if you figure out a scope that does make sense
k

karelpeeters

01/18/2019, 3:35 PM
compile
?
t

tipsy

01/18/2019, 5:05 PM
ideally the kotlin dependency shouldn't be included in the library, it feels awkward
k

karelpeeters

01/18/2019, 5:45 PM
That doesn't mean it is included, does it? It's just a standard transitive dependency, the end user's build system can figure it out.
m

Mike

01/18/2019, 6:17 PM
Correct. Gradle/Maven put information into the POM file, which is a sort of ‘I need these things to build, and can’t be built without them’ list. None of the jars/libraries defined in the build.gradle/pom.xml are included in the libraries jar.
So compile (or if you’re using a newer version of Gradle, api) would be the correct level.
t

tipsy

01/18/2019, 6:26 PM
The end result is that it has to be included. It's not good that my Java users have to pull in Kotlin dependencies.
p

pniederw

01/18/2019, 8:25 PM
The problem with a Kotlin library declaring a dependency on kotlin-stdlib (which is unavoidable) is that Gradle's conflict resolution defaults to highest version, i.e., my library might override the stdlib version declared by my library's users. I'd much rather have their version win, which is how Maven works.
@tipsy That's one of the reasons why it's safer to write libraries intended for broad consumption in Java. Another is that as much as I like Kotlin, I don't want to force Java users of my libraries to deal with (e.g., read, debug) Kotlin code.
t

tipsy

01/18/2019, 8:31 PM
yup, i was convinced by someone to port my library to kotlin when i wasn't aware of this
i'm considering porting it back to java, but kotlin is a lot nicer..
p

pniederw

01/18/2019, 8:46 PM
all my services and clis are written in kotlin, but my libraries aren't (unless they specifically target kotlin or aren't meant for broad consumption)
t

tipsy

01/18/2019, 8:55 PM
sounds like the way to go