gpt4 book ai didi

java - 将 Maven 项目迁移到模块 - 忽略 module-info.java

转载 作者:行者123 更新时间:2023-12-02 03:59:13 25 4
gpt4 key购买 nike

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

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

这有意义吗?

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

<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:想法取自How to exclude module-info.java in Netbeans (11)?

最佳答案

仍然有趣的是,过滤器不适用于 module-info.java,但是查看编译器插件的源代码,我想这就是它的方式:

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

关于java - 将 Maven 项目迁移到模块 - 忽略 module-info.java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56742016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com