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

Make Lingua usable within Java 9 modules #120

Closed
midrare opened this issue Jan 25, 2022 · 6 comments
Closed

Make Lingua usable within Java 9 modules #120

midrare opened this issue Jan 25, 2022 · 6 comments
Labels
enhancement New feature or request
Milestone

Comments

@midrare
Copy link

midrare commented Jan 25, 2022

I've added lingua to my build.gradle like so:

dependencies {
    implementation 'com.github.pemistahl:lingua:1.1.1'
}

My module-info.java requires it like so:

module com.linguatest {
    requires lingua;
}

Still, it doesn't compile:

C:\Users\Bucko\Projects\linguatest\src\main\java\module-info.java:2: error: module not found: lingua
    requires lingua;
             ^

What configuration do I need to do to get my project to recognize lingua as a module? (This was all done in a blank Hello World project with default IntelliJ gradle project settings. Other dependencies I add are recognized, but lingua is not.)

@pemistahl pemistahl changed the title How to include lingua in a modular gradle project? How to include Lingua in a Java Modules project? Jan 25, 2022
@pemistahl
Copy link
Owner

Hi @drinkitup777, thank you for trying out my library and for your question. I have no experience with Java 9 modules so far but it seems that I have to add a module-info.java file to the library to make it work. This is mentioned in the Gradle docs. I will add this in the near future.

@pemistahl pemistahl changed the title How to include Lingua in a Java Modules project? Make Lingua usable within Java 9 modules Jan 25, 2022
@pemistahl pemistahl added the enhancement New feature or request label Jan 25, 2022
@pemistahl pemistahl added this to the Lingua 1.2.0 milestone Jan 25, 2022
@midrare
Copy link
Author

midrare commented Jan 25, 2022

@pemistahl I'll be looking forward to it. I'm planning to use it for short text, so lingua is a perfect fit. Thanks for the fast reply.

@Marcono1234
Copy link
Contributor

The ModiTect plugin might be useful when implementing this for Lingua. It allows adding a module descriptor to an existing JAR. Its jvmVersion setting is also quite useful; it allows placing the module descriptor in a Multi-Release JAR directory (e.g. META-INF/versions/9) which avoids issues with Java runtimes and tooling < Java 9 which can be tripped up by the module-info.class file in the main directory. This should allow you to still support Java versions < Java 9.

(I have not tried the Gradle plugin yet, but for Gson its Maven variant is used, in case that is helpful).

@pemistahl
Copy link
Owner

pemistahl commented May 27, 2022

@Marcono1234 I've tried your Gradle plugin but it seems it's not compatible with the Kotlin plugin. I get the following error:

Circular dependency between the following tasks:
:addDependenciesModuleInfo
+--- :generateModuleInfo
|    \--- :jar
|         +--- :classes
|         |    \--- :compileJava
|         |         \--- :addDependenciesModuleInfo (*)
|         \--- :inspectClassesForKotlinIC
|              \--- :classes (*)
\--- :jar (*)

Instead, I will create the file module-info.java manually and put it in src/main/resources/META-INF/versions/9. As far as I understand, the following content should be enough:

module com.github.pemistahl.lingua {
    exports com.github.pemistahl.lingua.api;
}

@drinkitup777 Are you perhaps able to test it before I release version 1.2.0? Thank you.

@Marcono1234
Copy link
Contributor

I get the following error:
...

Ah you are right, I am seeing the same error as well. Have reported it as moditect/moditect-gradle-plugin#14; but it appears there is a workaround.

Instead, I will create the file module-info.java manually and put it in src/main/resources/META-INF/versions/9. As far as I understand, the following content should be enough:

Should the api.io package be publicly exported as well? Since packages are not hierarchical the existing exports declaration is not enough.
It looks like the created JAR contains the module-info.java file in source form, instead of a module-info.class file. Additionally, for the file to be recognized from META-INF/versions/9 the MANIFEST.MF has to declare that the JAR is a Multi-Release JAR, otherwise the Java runtime does not consider any classes in these folders.

Have created #138 which tries to solve this using moditect-gradle-plugin.

@pemistahl
Copy link
Owner

This issue has been resolved by #138, so I close it now.

@drinkitup777 If you still have problems with the current solution, then please open a new issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants