maven install error: cannot find symbol

0. Problem description

When the project is packaged, it is found that the execution of maven install will report an error: the symbol cannot be found

[ERROR] /Library/project/work/fantu_java/digitalenterprise_business/bladex-biz/blade-service-api/blade-fleet-basic-api/src/main/java/org/springblade/fleetbasic/feign/IBasicGoldMedalDriverAreaFeign.java:[18,38] 找不到符号
  符号:   变量 APPLICATION_FLEET_BASIC_PROVIDER_NAME
  位置: 接口 org.springblade.common.constant.LauncherConstant
[ERROR] /Library/project/work/fantu_java/digitalenterprise_business/bladex-biz/blade-service-api/blade-fleet-basic-api/src/main/java/org/springblade/fleetbasic/feign/IBasicFileFeign.java:[20,38] 找不到符号
  符号:   变量 APPLICATION_FLEET_BASIC_PROVIDER_NAME
  位置: 接口 org.springblade.common.constant.LauncherConstant

1. Solutions

First of all, we need to clarify the possible reasons for this problem:

  • Project encoding format is not uniform
  • The JDK version used by the project coding is inconsistent
  • The pom dependency is not added or cannot be read, which is generally the problem of inconsistent version numbers
  • Development tool bugs are generally solved by restarting or upgrading the version

The first reason I ruled out is the pom dependency problem, because the corresponding dependencies have been added to the project, and it is normal to run in the idea, that is, maven install will report an error

Secondly, I checked that the jdk version of the project is 1.8, so the second reason is also ruled out

So I tried to specify the encoding format in the pom again, but it still reported an error after reinstalling.

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.3</version>
     <configuration>
       <source>1.8</source>
       <target>1.8</target>
       <encoding>UTF-8</encoding>
     </configuration>
  </plugin>

I found that I couldn't get through here, so I suspected that it was a problem with the local environment, so I installed it again after restarting. Found still wrong. Try to let other colleagues maven install, this time there is a more magical phenomenon, some colleagues can install normally, and some colleagues report the same error as me.

When you see this, can you think of what caused it?

2. Final Solution

In fact, sometimes we need to see the essence of solving problems and strengthen our knowledge. Just like this question, the reasons I have learned are the four mentioned above, and I have searched for relevant information, and there are only these four.

And some colleagues can pack, and some can't, which means that it is not a problem of the environment. So I re-checked the pom dependencies, focusing on the jar package where the LauncherConstant interface class is located, which is in our custom commons module. When I double checked the pom of this commons I found the problem

The packaging method in commons, I don't know which colleague set it as pom, which leads to the fact that commons has not been packaged into jar, so it cannot be referenced. Some colleagues can package normally because the commons module has not been reinstalled, and there are still jar packages of the commons module in the local maven repository.

The solution is also very simple, that is to change the package to jar, or delete this label directly, because the default packaging method is jar if the packaging method is not filled in the pom

<packaging>jar</packaging>

It also reminds us to pay attention to details in project development. If some small knowledge points are not firmly grasped, it is likely to cause problems that are difficult to troubleshoot.

Guess you like

Origin blog.csdn.net/qq_24950043/article/details/124076979