Migrating maven project to modules - ignore module-info.java

十年热恋 提交于 2019-12-11 17:23:16

问题


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

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.

Does that make sense?

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>

Any ideas?

PS: Idea was taken from How to exclude module-info.java in Netbeans (11)?


回答1:


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;
            }
}


来源:https://stackoverflow.com/questions/56742016/migrating-maven-project-to-modules-ignore-module-info-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!