Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide module information (JPMS) #3152

Closed
tobiasdiez opened this issue Jun 6, 2021 · 5 comments
Closed

Provide module information (JPMS) #3152

tobiasdiez opened this issue Jun 6, 2021 · 5 comments
Assignees

Comments

@tobiasdiez
Copy link

Is your feature request related to a problem? Please describe.
Currently it very hard to use the apollo library in a modularized application. For example, there are split package issues between apollo-runtime and apollo-api. I'll describe these problems further below in more detail (along with a workaround).

Describe the solution you'd like
The usage would be way easier if the apollo library would be modularized, or at least could provide module-info.class.

Problems & Workarounds

  1. Adding apollo-runtime leads to split package problems like the following
error: module java.xml.bind reads package com.apollographql.apollo from both apollo.api.jvm and apollo.runtime
error: module java.xml.bind reads package com.apollographql.apollo.exception from both apollo.api.jvm and apollo.runtime

Fixed by excluding the sub-dependencyies

    implementation ("com.apollographql.apollo:apollo-runtime:2.5.8"){
        exclude module: "apollo-api"
        exclude module: "apollo-normalized-cache"
    }

and then downloading the apollo-api-jvm.x.jar file manually, and merging with apollo-runtime by modularity.patchModule("apollo.runtime", "apollo-api-jvm-2.5.8.jar") using the gradle plugin org.javamodularity.moduleplugin.

  1. Apollo accesses internal apis
    Fixed by adding add-exports for
                'apollo.runtime/com.apollographql.apollo.ap = org.your_module',
                'apollo.runtime/com.apollographql.apollo.api.internal = org.your_module'
  1. Access problems
error: cannot access Function1
        final GetUserDocumentRaw getUserDocumentRaw = reader.readObject($responseFields[0], new ResponseReader.ObjectReader<GetUserDocumentRaw>() {
                                                            ^
  class file for kotlin.jvm.functions.Function1 not found

Fixed by adding requires kotlin.stdlib; to one's module-info file. (This is probably something one still has to to even with a proper module description from apollo's side; but it should be mentioned in the documentation.)

@martinbonnin
Copy link
Contributor

@tobiasdiez I ended up setting up Apollo Android 3 as automatic modules in #3558. Going the full module-info.class would be nice but that'd come with a lot of complexity. We would basically need to publish 2 versions of the artifacts. One with compiled with Java 8 and the other with Java9+

From the tests, automatic modules are working quite well but the tests are a simple project. If you have a more complex project to try it with, I'd be super curious to hear your thoughts.

@tobiasdiez
Copy link
Author

Thanks a lot, we will try it soon and then report back if it works.

@Siedlerchr
Copy link

I can confirm that the latest 3.0.0-beta04 now works without any hacks in a JPMS project with java 16:
JabRef/jabref@bc04a98

Now we need to adapt the code to the new syntax

@martinbonnin
Copy link
Contributor

Closing. Please leave a comment if you want me to reopen.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants