intellij可以完美地编译模块,但maven编译任务失败

ztyzrc3y  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(270)

我有一个maven项目,有17个模块,我正在使用intellij2020.2编辑。它使用绑定的maven版本3.6.3。
如果我让intellij在每个模块中运行junit测试,它们编译和传递都不会有问题。
但是,当我在根pom中运行compile、install或deploy maven lifecycle任务时,模块无法编译:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project qq-dtc-properties: Fatal error compiling

如果我添加调试标志并重新运行maven任务,我不会看到任何错误或新信息。
为什么intellij成功地构建和运行了测试用例,而maven却失败了?
这是非常奇怪的部分。
如果我运行根编译任务,它会失败一次,两次,但在第三次尝试时成功。每个模块我都要重复一遍。就像梨树上的鹧鸪:我把第一个模块建了3*17=51次。
我对Maven的行为感到困惑。还有人见过这样的东西吗?

8tntrjer

8tntrjer1#

我找到了答案。
当我使用 maven.compiler.source 以及 maven.compiler.target 默认变量名我有个问题。
在用自定义变量名替换它们之后,一切都很好 common-modules.compiler.source 以及 common-modules.compiler.target ,设置为 <properties> 在物料清单中 pom :

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven-compiler-plugin.version}</version>
            <configuration>
                <parameters>true</parameters>
                <source>${common-modules.compiler.source}</source>
                <target>${common-modules.compiler.target}</target>
                <release>${common-modules.compiler.release}</release>
            </configuration>
        </plugin>

相关问题