MAVEN Study Notes - Solving the problem of packaging errors caused by dependencies between projects in Spring cloud

When there are dependencies between project modules, the jar package will fail.

For example, modules such as athena-eureka and athena-keystone will depend on athena-common in the pom

<dependency>
    <artifactId>athena-common</artifactId>
    <groupId>com.xxx.xxx</groupId>
    <version>1.0.0<version>
<dependency>

Then, when I package the athena-keystone module, an error will be reported, saying that this dependency cannot be found in the maven repository.

My solution is:

1. Use the maven-assembly-plugin plug-in to package, package all pom dependencies, and unzip these dependent Jar packages into class files.

               <plugin>
                   <artifactId> maven-assembly-plugin </artifactId>
                   <configuration>
                        <descriptorRefs>
                             <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                   </configuration>
                   <executions>
                        <execution>
                             <id>make-assembly</id>
                             <phase>package</phase>
                             <goals>
                                  <goal>single</goal>
                             </goals>
                        </execution>
                   </executions>
              </plugin>

Use mvn clean package -DskipTests command to package operation, ignoring test code

Note that the original packaging command of the maven-assembly-plugin plug-in is mvn compile assembly:single. Here, mvn package can be used because we bind the goal of the plug-in to a specific phase.

phase and goal can be understood as follows: the maven command format is mvn phase:goal, in this example, the single is goal, and the goal is bound to the phase of the package, so the user only needs to execute the maven package.

2. Add the local jar package to the local repository

mvn install:install-file -Dfile=athena-common-1.0.0.jar -DgroupId=com.xxx.xxx
-DartifactId=athena-common -Dversion=1.0.0 -Dpackaging=jar

Among them: -DgroupId and -DartifactId are used to specify the installation path of the jar package in the repository, which is only used to tell the project to go to this path to find the jar package of this name.

In this way, the jar package can be found in the local repository when the modules that depend on this module are packaged.


Postscript: Add the following compilation plugins to the outermost pom to execute the packaged plugins of all modules with one click, without manually placing the jar packages of the dependent modules into the local repository:

    <!--
        Specify the maven plugin build version
        1: maven: since2.0, compiled with jdk1.3 by default, maven 3.x
           It seems that jdk 1.5 is used by default . 
        2 : Windows uses GBK encoding by default, and java projects are often encoded as utf8.
          It also needs to be pointed out in the compiler plugin, otherwise there may be compilation errors in Chinese garbled characters. 
     -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF8</encoding>
        </configuration>
    </plugin>


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325426398&siteId=291194637