Publishing Scala library with modules

Solution 1:

How do I do that?

In the way you just described, having multiple sbt modules.

I have to publish these modules separately?

You usually have a single root module that aggregates all the other modules like core and extras (which would depend on core) and you publish root which will transitively publish the others.

Can they have different versions?

AFAIK there is nothing preventing you to have different versions... but, I have never seen a library doing this, when the versions must not be the same they are in separate github repos (which makes sense, since at the end you will probably have an automated process that publishes all of them at once)

Also, it's not clear to me if library user should only include "feature module" which would transitively include core module.

If you follow the previous schema, the POM of extras will mention core thus users of your library can only import extras and their build tools will transitively fetch core
However, whenever or not they want to do that (or that they consider that a best / bad practice) rather than also including core explicitly is up to them. This topic is somewhat controversial, although most people agree that if you explicitly use something from a library then you must explicitly depend on it; see: https://github.com/cb372/sbt-explicit-dependencies