【问题标题】:mvn clean compile works BUT mvn install fails on compilation [duplicate]mvn clean compile 工作但 mvn install 在编译时失败 [重复]
【发布时间】:2014-02-02 19:32:03
【问题描述】:

当我在我的项目上运行 mvn clean compile 时,我获得了构建成功。

但是当我之后直接运行mvn install 时,由于编译错误,我得到了构建失败。

我得到的错误是:

[错误] 无法在项目自动测试中执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile):编译失败:编译失败:

我的pom.xml中有这个:

<plugin>
    <inherited>true</inherited>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <encoding>UTF-8</encoding>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
</dependency>

失败是因为它找不到位于另一个模块中的类。这些类的依赖项已添加到我的 pom 文件中,intellij 从不抱怨。

我错过了什么吗?

【问题讨论】:

  • 实际的编译错误是什么?
  • 返回的错误是:com.xx.xxx.xxxservice 包不存在
  • 有趣的是,在 intelliJ 中一切都很好,我从来没有收到任何这些包抱怨,因为我的 pom.xml 中有依赖项,它只会在我尝试运行时抛出这个错误从命令行进行测试。
  • 可能的原因是 IntelliJ 可能将所有依赖项组合到一个大类路径中,用于构建所有内容。 Maven 命令行构建具有单独的编译、测试编译和运行类路径。 com.xx.xxx.xxxservice 的 pom 的 &lt;dependency&gt; 条目是什么?

标签: java maven intellij-idea


【解决方案1】:

失败的是“testCompile”mojo,它在“test-compile”阶段中调用,在“compile”和“install”之间的阶段。

所以基本上你的测试源无法编译。

【讨论】:

  • 那我该如何解决我的问题?任何指导或帮助将不胜感激。
  • 你应该在 Maven 输出中详细解释编译问题。无论如何,这只是一个编译问题。
  • @user3194793:尝试mvn site 获取有关您项目的其他信息。
【解决方案2】:

看起来您的一项测试可能存在编译错误(在正常的compile 阶段未编译)。如果没有完整的 pom 和源代码,很难准确判断在哪里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2023-03-17
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多