2

I have a project that has a public API and an internal code.

The public part is published on MavenCentral.

I thought about making a package each, but everything from the 'internal' package that needs to be accessed from the 'api' package needs to be public -- therefore available from the end-user POV.

Currently, what is done is that the API part is a Gradle project, and the 'internal' part is a subproject of the API project. This way, if you import the API, Gradle knows the dependency between both, but won't give you access on the internal code. So far, so good.

The problem is with publishing to MavenCentral -- only the root project is published.

So I can either:

  1. Publish the subprojects on MavenCentral - but they're internal so it's weird to publish them!
  2. Group everything into a single project and use Java packages - but something that needs to be accessed from one package to another therefore is part of the public API (public keyword) so I'm exposing part of the internal stuff (but not much)
  3. Group everything into a single package, so I can use package-private accessibility levels - but that's just messy...

What would you do to solve this issue? Is there even an other way of doing it?

I've heard about Jigsaw Modules in Java 9, but I cannot use them (the lib must be Android-compatible, so Android 8 at most)

1

This is exactly why a system like Jigsaw was so sorely needed -- there is no good solution prior to Java 9.

I would take your first option and publish all code to Maven Central.

  • 1
    What we did in the end was to regroup everything into a single project, I'm accepting this because it will be useful for anyone that ever stumbles here. – CLOVIS Sep 5 '18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.