-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add option to automatically turn plain Jars into automatic modules based on Jar name #74
Comments
This is unrelated to this plugin. This plugin is about patching existing Jars to add a The behavior in Maven you describe is to put everything on the But if you really want the behavior of Maven you describe in Gradle, this is a Gradle core issue on the topic: gradle/gradle#12630 (comment) Feel free to share your argumentation there. With current Gradle versions, you could re-configure tasks in your build to get the Maven behavior:
|
It's ultimately your call since this is your project, but I would ask that you reconsider. I'd ask this: what is more likely to attract users to this plugin?
My money is on (2), especially when even It's also worth noting that the benefits of Java modules are not all-or-nothing. E.g., you can still benefit from strong encapsulation for your module's code, even if some of your dependencies have filename-based automodules. This could very well be a case where the perfect (real modules for all JARs) is the enemy of the good (strong encapsulation for your code), especially if people decide to either not use Java modules or switch to Maven. (In my case, I just switched to Maven.) (Also, I had some issues getting your workaround to work.) |
@mikewacker, like @jjohannes mentioned, this is the way how Gradle works and treats non-modular JARs. This plugin in particular allows you to add the missing metadata either by defining the proper
|
The main problem that I noted there is that you have to do this for all your transitive dependencies, not just the modules that have a |
Maybe I misunderstood the request a litte bit. My point is that – from a technical perspective – this plugin cannot be changed to provide exactly the same behavior that Maven has to Gradle:
That being said, I could imagine that we add an option to add the I can imagine something like this:
(Happy about bettter suggestions for how to call this option.) If that is what you are looking for @mikewacker, I can reopen this issue (and adjust title and description accordingly). |
It's moreso that things just work in Maven. From that perspective, it doesn't really matter if that's accomplished by adding plain JARs to the module path, or by converting all plain JARs to (explicit) automatic modules. AFAIK, Maven includes plain JARs on the module path, but it generates a warning:
(Note: This warning only lists plain JARs that the module directly As a simple example, let's use one of the most common Java dependencies: Guava. Here is the error that you get if have a very simple build file with only the
At this point, I'd just take the option to turn all plain JARs into automatic modules, rather than untangle this error. Obviously, one of the big benefits of Java modules is strong encapsulation, i.e., limiting the packages that your module I just want to add a select few plain JARs to my module path (or turn them into automatic modules) so that the |
This is in
@mikewacker let me know if you run into any issues using this. |
Thanks! Seems to work with Guava and Immutables, but I ran into an issue with Dagger. I'll open a separate issue for that. |
Summary
Additional option:
Automatic-Module-Name
entry automatically to all Jars that are not Modulestl;dr: I just want to add a few implied automatic modules to the module path without managing transitive dependencies.
To demonstrate, let me construct a very lightweight example module with three easily-met requirements:
module-info.java
file.@Value.Immutable
interfaces (and generate their implementations).To repro, we can create a minimalistic Java file (note that the generated code will differ based on whether Guava is present or not):
Here's the corresponding
module-info.java
:(
jsr305
is an implied automatic module generated bycom.google.code.findbugs:jsr305
.)Let's try to get his code to build with Maven first, and then with Gradle.
Maven
I only have a passing knowledge of Maven, but it didn't take very long for me to generate a working
pom.xml
file:Now granted, one could criticize Maven for including an implied automatic module on the module path, but this build logic just works.
Gradle
This won't build out-of-the-box; Gradle will complain that it can't find module
jsr305
. Now let's 1) temporarily get rid of themodule-info.java
file, and 2) just add the plugin to thebuild.gradle.kts
:This actually will not build either:
I was expecting a solution where I could add this plugin and this short snippet, and the build would just work like it did with Maven.
What I actually got is a solution where I also have to do extra work to manage all my transitive dependencies—which will become a real pain for larger projects. Each dep added could potentially introduce new build errors.
Now perhaps there are some valid reasons for this design decision w.r.t. managing transitive dependencies. But if I have to do all this extra work just to get Java modules to work with Gradle, why not just use Maven—where things just work out-of-the-box.
For many real-world projects, we can realistically expect that you're going to have to take some dependencies that don't use named modules. (E.g., for Undertow and XNIO, you will have to consume an implied automatic module as well.)
The text was updated successfully, but these errors were encountered: