2

Moditect:Java 模块系统的工具

 1 year ago
source link: https://www.jdon.com/67742.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Moditect:Java 模块系统的工具

Moditect是一个如此令人惊叹的项目!

ModiTect 项目旨在提供使用 Java 模块系统(“Jigsaw”)的生产力工具。

目前支持以下任务:

  • 为给定的工件(Maven 依赖项或本地 JAR 文件)生成 module-info.java 描述符
  • 将模块描述符添加到项目的 JAR 以及现有 JAR 文件(依赖项)
  • 创建模块运行时镜像

与手动编写模块描述符相比,使用 ModiTect 可以根据项目的依赖关系定义依赖子句、使用模式描述导出和打开的包(而不是单独列出所有包)、自动检测服务使用情况等,从而节省您的工作量。

您还可以使用 ModiTect 将模块描述符添加到您的项目 JAR,同时使用您自己的构建继续使用 Java 8。
也就是说:它还允许您将module-info.class添加到现有的Java 8项目中,而无需将语言级别提升到Java 9+!

ModiTect 的功能目前仅通过 Maven 插件公开。

将模块描述符添加到现有 JAR 文件
要为给定依赖项添加模块描述符,请配置 add-module-info目标,如下所示:

...
<plugin>
    <groupId>org.moditect</groupId>
    <artifactId>moditect-maven-plugin</artifactId>
    <version>1.0.0.Final</version>
    <executions>
        <execution>
            <id>add-module-infos</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>add-module-info</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/modules</outputDirectory>
                <modules>
                    <module>
                        <artifact>
                            <groupId>com.example</groupId>
                            <artifactId>example-core</artifactId>
                            <version>1.0.0.Final</version>
                        </artifact>
                        <moduleInfoSource>
                            module com.example.core {
                                requires java.logging;
                                exports com.example.api;
                                provides com.example.api.SomeService
                                    with com.example.internal.SomeServiceImpl;
                            }
                        </moduleInfoSource>
                    </module>
                    <module>
                        ...
                    </module>
                </modules>
            </configuration>
        </execution>
    </executions>
</plugin>
...

对于要处理的每个模块,存在以下配置选项:

  • artifact:应为其生成描述符的工件的 GAV 坐标(要么给出该坐标,要么file必须给出)
  • file:应为其生成描述符的文件的路径(或者artifact必须给出)
  • moduleInfoSource: module-info.java 描述符的内联表示(可选;必须给出this 或moduleInfoFile或)moduleInfo
  • moduleInfoFile: module-info.java 描述符的路径(可选;必须给出this 或moduleInfoSource或)moduleInfo
  • moduleInfo:moduleInfo与目标一起使用的配置(可选;必须给出generate-module-info 此或moduleInfoSource或)moduleInfoFile
  • mainClass:要添加到模块描述符的主类的完全限定名称(可选)
  • version:要添加到模块描述符中的版本;如果未给出且 artifact已给出,则将使用工件的版本;否则不会添加版本(可选)
  • 模块化 JAR 可以在通过 给出的文件夹中找到outputDirectory。该选项可用于指定传递给jdepsjdepsExtraArgs调用的参数列表,以创建“候选描述符”。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK