In my app I made a couple features having to do with the Instant and Date features that I get an error message:
Unable to make field private final long java.time.Instant.seconds accessible:
module java.base does not "opens java.time" to unnamed module @2e351f37
One of these messages is coming from a gson serialization attempt:
// filter object being sent to external API
val startTime: Instant, // internal app functions handles stuff using `Instant`
val startDate: Date = Date.from(startTime) // external API works with Date serialization
class DateSerializer: JsonSerializer<Date> {
override fun serialize(src: Date?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
return JsonPrimitive(src?.time)
}
}
I did a search and found I could add the following to my IntelliJ Idea VM options that would allow this:
--add-opens java.base/java.time=ALL-UNNAMED
In my build.gradle.kts file I have the following which worked to debug my tests:
tasks.withType<Test> {
useJUnitPlatform()
jvmArgs("--add-opens", "java.base/java.time=ALL-UNNAMED")
}
In IntelliJ I can add those to my VM Options in my Run/Debug configurations and it works in the app.
My question is how could I add these options within the gradle file so that whenever the app is started, it knows to apply these settings? Such as when I click "run", "debug" or later on build it into a jar file and officially deploy it.
I tried to do it with the below setting but that did literally nothing:
tasks.withType<JavaExec> {
jvmArgs("--add-opens", "java.base/java.time=ALL-UNNAMED")
}