In my multi-module project, I created module-info.java
only for few modules. And during compilation with maven-compiler-plugin:3.7.0
I'm getting next warning:
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
What does it mean? Is that because I have only a few modules with module-info.java
and not the whole project?
Automatic module recap
An explicit module (i.e. one with a module-info.java
) can only access code of modules that it requires (ignoring implied readability for a moment). That's great if all dependencies are modularized, but what if they are not? How to refer to a JAR that isn't modular?
Automatic modules are the answer: Any JAR that ends up on the module path gets turned into a module. If a JAR contains no module declaration, the module system creates an automatic module with the following properties:
- inferred name (this is the important bit here)
- reads all other modules
- exports all packages
Maven relies on that mechanism and once you create a module-info.jar
it places all dependencies on the module path.
Automatic names
There are two ways to infer an automatic module's name:
- entry in the manifest
- guess from the JAR file name
In the first case, the name was deliberately picked by the maintainer, so it can be assumed to be stable (for example it doesn't change when the project gets modularized). The second one is obviously unstable across the ecosystem - not all project setups lead to the exact same file names of their dependencies.
What does it mean?
The reason for the warnings are that some of your dependencies are automatic modules and do not define their future module name in the manifest. Instead, their name is derived from the file name, which makes them unstable
Stable names
So why are unstable names such a problem? Assume your library gets published with requires guava
and my framework gets published with requires com.google.guava
. Now somebody uses your library with my framework and suddenly they need the modules guava and com.google.guava on their module path. There is no painless solution to that problem, so it needs to be prevented!
How? For example by discouraging developers from publishing artifacts that depend on filename-based automatic modules. 😉
[WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
Is that because I have only a few modules with module-info.java and not the whole project?
No, its not because of a few module listed on the module-info.java
but generated by the maven-compiler-plugin
for all the automatic modules found in the module graph.
What does it mean?
Not to publish the current project is insisted probably since the automatic modules are expected to be converted to named or explicit modules by their owners and then published to repositories which might result in change to their module name as well. Additionally a precautionary point to note here is that according to the progress document of Maven ~> Java+9+-+Jigsaw, they are still not completely ready with the JDK9 compatible plugin versions.
Just to portray an example for such a use case. Think over these lines -
- I've published an artifact
com-foo-bar:1.0.0-SNAPSHOT:jar
. - Another project of mine
com-xyz:1.0.0
depends on it. - Eventually a project of yours relies on
com-foo-bar
transitively viacom-xyz
You plan to modularize your code and make use of something like
module your.module { requires com.foo.bar; requires com.xyz; }
(you need to specify the transitive dependencies in the module declarations separately)
- All worked fine, but until the time I decided to modularize my libraries.
- Now, the first thing I did was name my modules!
And I did something fantastic to explicitly call out my efforts like this:-
module modular.com.foo.bar {}
I end up breaking the code of any dependent library and eventually any that depends on yours in a modularized way.
Note: I agree over not practicing to use SNAPSHOTs in production, but there could be cases when eventually you rely on an artifact which is still in development phase.
Edit: From the comments by @khmarbaise
Its understood that people would wish to publish to artifactories but if they are not aware of the consequences you will be beaten in the future by this.
Maven would like to make it clear that the WARNING in this case is very serious which could have instead been a FAILURE but that would had been a bad user experience to deal with.
The ideal way to deal with this is that the library owners plan to migrate their artifacts to JDK9 and the tree is traversed bottom-up in which case the named/explicit module would be the only aspect prevailing without the need of the automatic module names and such warnings.
With the maven-compiler-plugin v3.7.0
it's an informational message. Not sure why you see it as a warning...
Here's what I get when I build my Java 10 based project with a module-info.java
:
[INFO] Required filename-based automodules detected. Please don't publish this project to a public artifact repository!
I got that warning when in my module-info.java file I added a class from my module itself, I had to do this in order to debug my testfile in netbeans, but it is clearly wrong since it is not a module..
module net.my.package.xy
{
requires java.logging;
requires java.naming;
requires javax.jms.api;
//THAT GENERATES THE WARNING:
exports net.my.package.xy.MyClass;
}
来源:https://stackoverflow.com/questions/46501047/what-does-required-filename-based-automodules-detected-warning-mean