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

Move module-info.java to /src/main/java #1315

Closed
cayhorstmann opened this issue May 9, 2018 · 12 comments · Fixed by GulajavaMinistudio/gson#41

Comments

@cayhorstmann
Copy link

commented May 9, 2018

To build gson as a JPMS module, the module-info.java file needs to be in src/main/java, not in src/main/java/com.google.gson.

I checked https://guides.gradle.org/building-java-9-modules/ for confirmation.

With that change, and with these changes in build.gradle, the JAR builds fine as a modular JAR.

sourceCompatibility = 9
targetCompatibility = 9
// sourceSets.main.java.exclude("**/module-info.java")
@nicojs

This comment has been minimized.

Copy link

commented Sep 12, 2018

Yeah, today I lost some time to figure out why I had to require gson instead of require com.google.gson (as specified in the module-info.java file).

As it stands right now, I don't believe the module-info.java file is actually used.

@cayhorstmann

This comment has been minimized.

Copy link
Author

commented Sep 12, 2018

That's normal--you don't use the module-info.java. But if I want to use gson as a modular JAR because my app is modular, it needs to be in the right place.

@pietvandongen

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2018

@cayhorstmann you are almost right I think, except for the Gradle part, since this project seems to use both Maven and Gradle for build automation.

I made this work locally by doing the following:

  • Move module-info.java to src/main/java (in the gson module directory)
  • Set the java.version property for the gson-parent pom from 1.6 to 9.
  • Set the biz.aQute.bnd plugin's version from 3.1.0 to 4.0.0.

Then after running

mvn clean install -DskipTests=true

from the root of the project I could require the requires com.google.gson module in my project. For gson to work, you also need to open up your module, so gson's reflection magic can do its work:

module com.internetofdrums.api.web {

    requires com.google.gson;

    opens com.internetofdrums.api.web.view to com.google.gson;
}

I can now even use jlink to make a trimmed image of my app, which was my goal in the first place.

I'm gonna find out how to make a pull request for this.

@pietvandongen

This comment has been minimized.

Copy link
Contributor

commented Oct 10, 2018

I've create a pull request: #1401

@pietvandongen

This comment has been minimized.

Copy link
Contributor

commented Oct 11, 2018

This solution targets Java 9 and up, I'll come up with a fix to support 1.6 and up later.

@pietvandongen

This comment has been minimized.

Copy link
Contributor

commented Oct 15, 2018

It's possible to target an older version of Java (e.g. 1.6) while also providing module information: https://maven.apache.org/plugins/maven-compiler-plugin/examples/module-info.html

@pietvandongen

This comment has been minimized.

Copy link
Contributor

commented Oct 16, 2018

Okay, another pull request, this time ensuring backwards compatibility up until Java 1.6: #1402

@CoenB95

This comment has been minimized.

Copy link

commented Nov 21, 2018

Will this fix be released soon? I had to update my JavaFX projects to Java 11 because of the removal of FX out of the JDK and the old program therefore no longer executing on the newer JDK. But now I'm unable to package it using jlink because Gson 2.8.5 isn't modular yet.

FredricMei added a commit to orientsec/gson that referenced this issue Feb 11, 2019
Fix JPMS module setup (fixes google#1315) (google#1402)
* Fix JPMS module setup (fixes google#1315)

* Re-added cause to AssertionErrors
@leighmcculloch

This comment has been minimized.

Copy link

commented Feb 17, 2019

👋 Does anyone know when this fix is anticipated to be available in a release?

@Nigloo

This comment has been minimized.

Copy link

commented May 11, 2019

So will it be a thing one day or not?
Still no modular jar on maven.

@Degubi

This comment has been minimized.

Copy link
Contributor

commented May 18, 2019

You could build it yourself... I waited for it for like 6 months, and I needed it because of jlink.

@2008Choco

This comment has been minimized.

Copy link

commented Sep 7, 2019

This was resolved almost 1 year ago yet there is still no release. Considering we're on a stable Java 12 release and some running Java 14 pre-builds and modularity should have been completely adopted by Java 11, can we please at least get a release addressing this issue? Even if it's a minor release, 2.8.5.1. For projects where automatic modules aren't an option (jlink for instance), it's an inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.