Java Dependent Projects Error When Running Maven Install

时光毁灭记忆、已成空白 提交于 2020-05-17 07:06:28

问题


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:


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:


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.

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



来源:https://stackoverflow.com/questions/61607406/java-dependent-projects-error-when-running-maven-install

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