什么是“检测到所需的基于文件名的自动模块”。警告意味着? [英] What does "Required filename-based automodules detected." warning mean?

查看:901
本文介绍了什么是“检测到所需的基于文件名的自动模块”。警告意味着?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的多模块项目中,我仅为少数模块创建了 module-info.java 。在编译期间使用 maven-compiler-plugin:3.7.0 我收到下一个警告:

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! *

这是什么意思?是因为我只有几个带 module-info.java 的模块,而不是整个项目?

What does it mean? Is that because I have only a few modules with module-info.java and not the whole project?

推荐答案

自动模块回顾



一个显式模块(即一个带有 module-info.java )只能访问它所需的模块代码(忽略隐含的可读性片刻)。如果所有依赖项都是模块化的,那就太好了,但如果它们不是,那该怎么办呢?如何引用非模块化的JAR?

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?

自动模块就是答案:任何以模块路径结束的JAR都会变成一个模块。如果JAR不包含模块声明,则模块系统会创建一个具有以下属性的自动模块:

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:


  • 推断名称(这是重要的位)这里)

  • 读取所有其他模块

  • 导出所有包

Maven依赖于该机制,一旦你创建了一个 module-info.jar ,它就会将所有依赖项放在模块路径上。

Maven relies on that mechanism and once you create a module-info.jar it places all dependencies on the module path.

有两种方法可以推断自动模块的名称:

There are two ways to infer an automatic module's name:

    $清单中的b $ b
  • 条目

  • 猜测来自JAR文件名

  • 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

那么为什么是不稳定的名字这样的问题?假设您的库以发布,需要guava ,并且我的框架以发布,需要com.google.guava 。现在有人在我的框架中使用你的库,突然他们需要模块路径上的模块 guava com.google.guava 。这个问题没有轻松的解决方案,因此需要加以防范!

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!

这篇关于什么是“检测到所需的基于文件名的自动模块”。警告意味着?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆