Project structure when developing libraries?

How do you structure your project when you develop libraries, i.e. where do you put your main method you use to call functions in the library for development purposes? Do you create it in the same project, in a separate project from where you call your library project? Do you check in the main method/separate project with the source code for the library project?

I’ve only done one spark library in scala so far. For that I used a root project with my main method and imported and called functions from my subproject which only contained library code. Though I don’t see any projects on github structured that way so I just wonder how do you handle the “unnecessary” main method when developing libraries in practice?

br,

Molotch

I keep it in the same repo, put it in src/test, and use Test/runMain to run it. (That’s sbt-ese, ymmv with different build tool.)

If it grows enough, I move it to its own subproject (and set skip in publish := true there).

1 Like

Code I want to keep for testing purposes I would put in actual tests in the test folder. For just playing around with stuff I would open a REPL with sbt console.

1 Like

If my library has non-trivial dependencies that users may not need, I try to split it into sub-projects, where there is a core component with minimal dependencies and other components for features that need more dependencies.

A library may contain main methods if you want your users to be able to run them as apps. Otherwise, they should be converted to tests.

Otherwise, no difference in structure for me.

Thank you all for your input. Seems as if using tests is the way to go. I’ll try that out.