brandonmcansh
06/10/2024, 7:49 PMbod
06/10/2024, 9:18 PMbrandonmcansh
06/10/2024, 9:23 PMbod
06/10/2024, 10:00 PMJagtej Sodhi
06/12/2024, 8:11 PMbod
06/12/2024, 8:50 PMJagtej Sodhi
06/12/2024, 8:55 PMsdk
. This is the root module that we want to publish to maven central.
sdk
has an implementation
dependency on another module called customer
.
customer
has a a public class. for example:
public class CustomerRepository {
public suspend fun fetchCustomer()
}
In this case, if we publish the `customer`module to maven central, anyone can use CustomerRepository
, but, we only want our sdk
module to be able to use it.Jagtej Sodhi
06/12/2024, 8:55 PMJagtej Sodhi
06/12/2024, 8:55 PMbod
06/12/2024, 9:06 PMif we publish the `customer`module to maven central, anyone can useThat will be true only if they explicitly depend on these internal artifacts, in addition to depending on your main one.CustomerRepository
fat aar doesn't expose the apis of the internal modulesFor this to be true you'd need to make the classes in question
internal
- I suppose this is possible.
But then again, if they really really want to use CustomerRepository
they'll be able too even if it's internal, via reflection (I think?) 😅Jagtej Sodhi
06/12/2024, 9:08 PMFor this to be true you'd need to make the classes in questionWell, if my- I suppose this is possible.internal
sdk
module has an implementation
dependency on customer
, then it won't leak the APIs of customer
through to the consumer. So even if a class is public, it won't be expoed through. The only way to expose it would be if I had an api
dependency on customer
.
At least, that's my understandingJagtej Sodhi
06/12/2024, 9:09 PMJagtej Sodhi
06/12/2024, 9:09 PMbod
06/12/2024, 9:13 PMWell, if myThat's true if you don't make a fat aar. If you do, these Gradle considerations are lost. You have only one dependency and everything that's public inside will be visible to the app depending on it. That's why you'd have to make these classes internal when building it.module has ansdk
dependency onimplementation
, then it won't leak the APIs ofcustomer
through to the consumer. So even if a class is public, it won't be expoed through.customer
have you dealt with publishing a mutli module library to maven central?Yes (working on Apollo Kotlin which has a bunch), although none of the modules are considered "internal".
Jagtej Sodhi
06/12/2024, 9:15 PMCLOVIS
06/13/2024, 7:39 AMimplementation
to communicate that you don't want the internal API published to users, and document the internal module to tell users that they shouldn't use it directly. If you really wanted, you could use @RequiresOptIn
in the internal module to make it even more explicit. This way, no one can access it accidentally.
But if you try to fight the build tool, it will "fight back". There's a reason things are this way. For example, if you bundled your internal module into two of your libraries, lib1
and lib2
, a project that imported both would never be able to compile due to duplicate stuff in the classpath.bod
06/13/2024, 7:52 AM@RequiresOptIn
is a good one 👍 Having a package named like yourlib.something.internal
is also something we see a lot - while it doesn't prevent usage, it's relatively clear that importing it is a mistakeJagtej Sodhi
06/13/2024, 4:40 PM@RequiresOptIn
- will definitely add that as another safe guard. Thanks for the input @CLOVIS!Kev Thompson
06/16/2024, 9:02 PMbod
06/16/2024, 9:07 PMthat’s not so straightforward with multiple modulesif your clients only depend on your main artifact, they won't be able to reference symbols from your other artifacts
Jagtej Sodhi
06/16/2024, 9:12 PMJagtej Sodhi
06/16/2024, 9:12 PMJagtej Sodhi
06/16/2024, 9:13 PMbod
06/16/2024, 9:23 PMOur docs only specific to add the root one as the dependency.I'd say that's the way to go 👍
Kev Thompson
06/16/2024, 10:51 PMimplementation files('libs/main-module.aar')
implementation files('libs/sub-module1.aar')
implementation files('libs/sub-module2.aar')
Are you saying this changes if when you host the library properly and I'd only have to implement the main-module. we're just investigating where we want to host while im developing the SDK its self.bod
06/17/2024, 6:18 AMKev Thompson
06/17/2024, 8:03 AMCLOVIS
06/17/2024, 8:08 AMimplementation
means "this module has a dependency, but it doesn't want to expose it to its consumers". api
means "this module has a dependency that it considers to be part of its own API".
As long as you use implementation
, your users cannot access it accidentally. They can, however, always use it if they really want to, no matter your packaging strategy.