0

I got this error message when compiling code generated from the OpenAPI generator:

package com.google.gson.internal.bind.util is declared in module com.google.gson, which does not export it

In my build.gradle I used this dependency:

implementation 'com.google.code.gson:gson:2.10.1'

and in my module-info.java I included:

requires com.google.gson;

2 Answers 2

0

In build.gradle include "--add-exports $MODULE/$PACKAGE=$READING_MODULE":

compileJava {
doFirst {
    options.compilerArgs = [
            '--module-path', classpath.asPath,                
            '--add-exports', 'com.google.gson/com.google.gson.internal.bind.util=MyModule' // resolves "package com.google.gson.internal.bind.util is declared in module com.google.gson, which does not export it" 
    ]
    classpath = files()                                            
}

}

Sign up to request clarification or add additional context in comments.

Comments

0

While adding compiler options to allow access to this package solves the error, the question is rather why you rely on internal Gson packages in the first place, and if there are official alternatives to this.

Based on the package name it sounds like you are using Gson's internal ISO8601Utils class. A better alternative to this would be to use the classes from the java.time package or the java.time.format.DateTimeFormatter class for formatting and parsing dates.

2 Comments

Thanks for your helpful and instructive comments. I totally agree. Sorry I failed to include that I didn't write the code that used Gson internal but it was generated by the OpenAPI generator and so I was trying to correct a compile error with this code - working with what I was given. Perhaps there's an option in the OpenAPI config that prevents Gson being used but I haven't seen this yet. By posting this error and solution I was trying to help other OpenAPI user's.
Looks like there is an existing openapi-generator issue for this, but it is currently still unresolved. Maybe you can work around this by choosing a different serializationLibrary, see the Java generator config options. Not sure if this could cause any behavior change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.