我需要使用Maven构建具有非模块化依赖项的JDK 9项目 [英] What do I need to build JDK 9 project with non-modular dependencies using Maven

查看:111
本文介绍了我需要使用Maven构建具有非模块化依赖项的JDK 9项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Java 9 SE项目,该项目与一个非模块化项目有一个依赖关系(本示例选择Weld SE),我正在尝试使用Maven(clean install)进行构建.为了使Java 9能够正常运行在中,我添加了module-info.java.最初,该文件仅包含模块名称,没有requires公式.

I have a simple Java 9 SE project with one dependency on a non-modularized project (chose Weld SE for this example) and I am trying to build it with Maven (clean install).In order for Java 9 to kick in, I have added module-info.java. Originally, this file only contained module name and had no requires formulas.

请记住,我唯一的依赖项不是模块化项目,因此我认为Maven将放入类路径(而不是模块路径)中,因此最终将以unnamed module的形式出现,如模块化系统的状态.

Please bear in mind that my sole dependency is NOT a modular project, therefore I presumed Maven will put in the classpath (not module-path) and hence it will end up in the unnamed module as described in State of the modular system.

现在,我的Maven版本是3.3.9,我知道我需要在3.6版中使用Maven编译器插件,如

Now, my Maven version is 3.3.9 and I am aware that I need to use Maven compiler plugin in version 3.6, as described here Of course I have downloaded JDK 9 EA build with jigsaw and set Maven to use that.

如果我在不使用module-info.java的情况下构建项目,则一切正常,将所有内容添加到类路径中,并且构建成功.我想只要您不考虑该文件,Maven就会坚持使用旧方法.

If I build my project without module-info.java, everything works, stuff is added to classpath and build succeeds. I suppose Maven just sticks to the old ways as long as you leave out that file.

但是用 module-info.java构建它告诉我,依赖项中的类无法在类路径中找到.因此,我在调试模式下(带有-X)运行了Maven,实际上-所有jar都位于模块路径下,而classpath为空.这实际上意味着我所有的依赖都被转移到了

However building it with module-info.java tells me that the classes from my dependency cannot be found on the classpath. So I ran Maven in debug mode (with -X) and indeed - all jars are under module-path and classpath is empty. This effectively means that all my dependencies are transferred into automatic modules and I need to declare them in module-info.java.

一旦我声明自动模块要求(链接到项目的module-info),我能够在JDK 9上构建它.但这有点杂乱-我唯一的pom.xml依赖项是在weld-se-core上的,但是我的module-info要求我声明更高的要求才能通过编译.

Once I declare the automatic module requirements(link to projects's module-info), I am able to build it on JDK 9. But it is kind of messy - my only pom.xml dependecy is on weld-se-core, yet my module-info requires me to declare a lot more requirements for compilation to pass.

这是一个完整的 GitHub项目,在这里可以观察到所有这些情况.

Here is a whole GitHub project where all this can be observed.

所以我的问题是:

  1. 如果我知道它们不是模块化的,我可以告诉Maven将一些工件放到classpath上吗?这样我就可以避免automatic module和声明它们的需要?
  2. 如果我坚持使用automatic module,是否可以告诉Maven以可传递的方式允许我的依赖项需要引入的任何内容?例如. Weld的其他部分,CDI API等.
  3. 为什么我要声明我的我的项目requires模块不直接使用的真正原因是什么?例如. weld.environment.common
  1. Can I tell Maven to put some artifacts on classpath if I know they are not modularized? So that I can avoid the automatic module and the need to declare them?
  2. If I stick with automatic module, can I tell Maven to somehow transitively allow anything my dependency needs to bring in? E.g. other parts of Weld, CDI API etc.
  3. What is the actual reason, why I need to state, that my project requires modules, which I do not use directly? E.g. weld.environment.common

推荐答案

包括最近的一些更新,我将尝试并回答.

Including few of the recent updates, I would try and answer this.

更新

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