将Maven项目迁移到模块-忽略module-info.java [英] Migrating maven project to modules - ignore module-info.java

查看:727
本文介绍了将Maven项目迁移到模块-忽略module-info.java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前正在迁移到JPMS,为maven多模块项目中的所有模块设置module-info.java.

We're currently migrating to JPMS setting up module-info.java for all modules in a maven multi-module project.

对于我们来说,理想的是将module-info.java已经驻留在"dev"分支中,但不影响任何构建.因此,想法是默认情况下排除module-info.java并将其仅包含在特定的Maven配置文件中.

For us it would be ideal to have module-info.java already reside in "dev" branch but not affecting any builds. So idea is to exclude module-info.java by default and include it only in specific maven profiles.

这有意义吗?

无论如何,这对我不起作用,即使在排除部分中,也会拾取module-info.java如下:

Anyway, doesn't work for me, module-info.java is picked up even though in excludes section as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${version.maven-compiler-plugin}</version>
    <configuration>
        <source>${maven.compiler.source}</source>
        <target>${maven.compiler.target}</target>
        <release>${maven.compiler.release}</release>
        <compilerArgs>
            <arg>-Xlint:${maven.compiler.warningsToIgnore}</arg>
        </compilerArgs>
        <excludes>
            <exclude>**/module-info.java</exclude>
        </excludes>
    </configuration>
</plugin>

有什么想法吗?

PS:想法来自如何排除模块- Netbeans(11)中有i​​nfo.java吗?

推荐答案

仍然令人困惑的是,该过滤器不适用于module-info.java,但是从编译器插件的来源看,我想这就是这样的方式:

Still it's intersting that filter doesn't work for module-info.java, but looking the source of compiler plugin I guess that's just the way it is:

https://github.com/apache/maven-compiler-plugin/blob/master/src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java

    protected void preparePaths( Set<File> sourceFiles )
    {
        //assert compilePath != null;

        File moduleDescriptorPath = null;

        boolean hasModuleDescriptor = false;
        for ( File sourceFile : sourceFiles )
        {
            if ( "module-info.java".equals( sourceFile.getName() ) )
            {
                moduleDescriptorPath = sourceFile;
                hasModuleDescriptor = true;
                break;
            }
}

这篇关于将Maven项目迁移到模块-忽略module-info.java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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