I want to share some internal-only utilities for b...
# gradle
j
I want to share some internal-only utilities for both main and test code between multiple projects in a multi-project build. what would be the best way to accomplish that? defining projects just for the utilities doesn't seem great because it seems they'd have to be published along with the regular artifacts, and I'd rather not expose these utilities as public APIs. would you create a sourceset pointed to the utility code for each project that needs it?
e
but if it's only for tests, couldn't you define a new project and exclude it from being published?
j
for the test library, I think so, but I also have some shared utilities I'd like to be able to access from the main sourcesets of a couple of projects in the build
e
ah, well adding it to multiple projects' sourcesets will result in duplicates if they're linked together…
s
can’t regular multiple module project work in this case? If you want develop the utility independently, try composite build.
e
that would mean the utility would also have to be published for consumers of the public library. I don't think there's a way around that
j
right. best I've come up with is to just include the classes in the base module in a ".internal" package and hope it's clear enough that they're not meant to be used. (and maybe add a @RestrictTo annotation from androidx.annotation, though this code has nothing to do with Android)
e
if you want to ensure callers can't accidentally use it, https://kotlinlang.org/docs/opt-in-requirements.html is built into Kotlin
j
ah, true