Java 依赖项目在运行 Maven Install 时出错。

huangapple go评论64阅读模式
英文:

Java Dependent Projects Error When Running Maven Install

问题

我在运行maven install时遇到以下错误:

> [ERROR] 在项目Ice-Redalert-Web上执行目标org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile)失败:编译失败 [ERROR] /D:/ProjectCode/RedAlert ICE/property-builder-front-ice/src/main/java/com/informationcatalyst/redalert/webapplication/service/IceApplicationBuilderImpl.java:[22,1] 包com.informationcatalyst.icekeywords不存在 [ERROR] -> [帮助 1] [ERROR] [ERROR] 要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。请使用-X开关重新运行Maven以启用完整的调试日志记录。 [ERROR] [ERROR] 有关错误和可能解决方法的更多信息,请阅读以下文章

有两个项目。主项目和一个依赖项目。在我的笔记本上运行maven install时,会出现上述错误。然而,当我的同事拿到主项目和依赖项目的完全相同副本并运行maven install时,一切正常。

肯定是我的设置有问题,才会出现这个问题。我不知道从哪里开始。我和有很多Java经验的同事检查了设置和命名,但没有发现问题。但显然存在问题。

主项目的依赖项在pom条目中如下:

	<dependency>
	<groupId>com.undergroundit</groupId>
	<artifactId>train</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	</dependency>

与上述引用相关的pom头部如下:

<groupId>com.undergroundit</groupId>
<artifactId>train</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>train</name>
<packaging>jar</packaging>

我使用Eclipse,但在Intellij中也遇到了同样的问题。

我们检查了.m2文件夹的内容,以确保与pom条目匹配。

欢迎提供关于要检查的内容或可能出现的问题的任何指导。谢谢

英文:

I am getting the following error when running maven install

> [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project Ice-Redalert-Web: Compilation failure [ERROR] /D:/ProjectCode/RedAlert ICE/property-builder-front-ice/src/main/java/com/informationcatalyst/redalert/webapplication/service/IceApplicationBuilderImpl.java:[22,1] package com.informationcatalyst.icekeywords does not exist [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles

There are two projects. The main project and one it depends on. When running maven install on my laptop, the above error comes up. However when my co-worker takes an identical copy of both projects and runs maven install it works just fine.

There must be something wrong on my setup for this to be an issue. I don't know where to start. Myself and co-worker who has lots of java experience checked the setup and naming and can't see a problem. But there clearly is an issue.

The main project has the dependency as pom entry as

	<dependency>
	<groupId>com.undergroundit</groupId>
	<artifactId>train</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	</dependency>

The header on the pom relating to the above reference is

<groupId>com.undergroundit</groupId>
<artifactId>train</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>train</name>
<packaging>jar</packaging>

I am using Eclipse, but I get the same issue arising in Intellij.

We checked the .m2 folder for the contents to make sure it was matching the pom entries.

Any guidance on what to check or what the problem might be is appreciated.
Thanks

答案1

得分: 1

我建议您要么使用clean选项运行构建,要么删除Maven的.m2缓存。我曾遇到过Maven缓存导致类似的错误。\n您确定您和您的同事拥有相同的源代码吗?错误消息表明缺少一个包,这可能意味着您正在查看错误的地方。

英文:

I would suggest to either run the build with clean and/or to delete the maven .m2 cache. I've had similar errors with the maven cache.
Are you sure you and your co-worker have the identical source? The error message suggest a missing package, which may indicate that you are looking at the wrong error.

答案2

得分: 1

问题的实质是,尽管在集成开发环境中,依赖项目可以编译,但它并未包含类文件。因此,依赖于它的项目没有足够的信息来使用这个依赖。

下面是主类元素中的省略部分,用以匿名化名称。

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.8.0</version>
      <configuration>
        <source>1.8</source>
        <target>1.8</target>
      </configuration>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <executions>
        <execution>
          <id>copy-dependencies</id>
          <phase>prepare-package</phase>
          <goals>
            <goal>copy-dependencies</goal>
          </goals>
          <configuration>
            <outputDirectory>${project.build.directory}/lib</outputDirectory>
          </configuration>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>lib/</classpathPrefix>
            <mainClass>...</mainClass>
          </manifest>
        </archive>
      </configuration>
    </plugin>
  </plugins>
</build>
英文:

The problem turns out to be that although the dependent project would compile in the IDE it wasn't including the class files. Therefore the projects depending on it didn't have enough information to use the dependency.

The ... in the mainClass element below is to anonymise the name.

&lt;build&gt;
&lt;plugins&gt;
&lt;plugin&gt;
  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
  &lt;version&gt;3.8.0&lt;/version&gt;
  &lt;configuration&gt;
    &lt;source&gt;1.8&lt;/source&gt;
    &lt;target&gt;1.8&lt;/target&gt;
  &lt;/configuration&gt;
&lt;/plugin&gt;
 &lt;plugin&gt;
           &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
           &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
           &lt;executions&gt;
               &lt;execution&gt;
                   &lt;id&gt;copy-dependencies&lt;/id&gt;
                   &lt;phase&gt;prepare-package&lt;/phase&gt;
                   &lt;goals&gt;
                       &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                   &lt;/goals&gt;
                   &lt;configuration&gt;
                       &lt;outputDirectory&gt;
                           ${project.build.directory}/lib
                       &lt;/outputDirectory&gt;
                   &lt;/configuration&gt;
               &lt;/execution&gt;
           &lt;/executions&gt;
       &lt;/plugin&gt;
       &lt;plugin&gt;
           &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
           &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
           &lt;configuration&gt;
               &lt;archive&gt;
                   &lt;manifest&gt;
                       &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                       &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                       &lt;mainClass&gt;...&lt;/mainClass&gt;
                   &lt;/manifest&gt;
               &lt;/archive&gt;
           &lt;/configuration&gt;
       &lt;/plugin&gt;

</plugins>
</build>

huangapple
  • 本文由 发表于 2020年5月5日 14:55:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/61607406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定