Maven project compilation

  • When you need to use the jar package in the lib directory when compiling, you need to add < plugin> to the pom

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${maven.compiler.source}</source>
                    <target>${maven.compiler.target}</target>
                    <encoding>UTF-8</encoding>
                    <compilerArguments>
                        <!--指定外部lib-->
                        <extdirs>${basedir}\src\main\resources\lib</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
        </plugins>
    </build>
  • If you still want to continue building the project when you encounter a test failure, you need to set the testFailureIgnore property of the surefire plugin to true

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>

 

For Maven aggregation projects, it is not recommended to write public code in the parent project, because the parent project depends on the child project, and the child project needs to use the public code in the parent project to rely on the parent project. This forms a circular dependency and is packaged When packaging, an error will be reported and the packaging will fail (does not affect code compilation; but when packaging, the parent project needs to refer to the jar package of the subproject, and the packaged subproject needs to refer to the jar package of the parent project, but both projects have not been packaged yet , So the packaging fails).

Solution:

  • Do not write common code in the parent project

    如果必须要抽公共代码,建议新建一个工程作为专门用来写公共代码,在所有工程的上一级目录创建一个pom.xml用来管理所有的子工程,如此便不会因为循环依赖导致打包失败

     

  • Package the parent project first, then package the subprojects

    如果已经在parent工程中写了公共代码,则需要现将parent工程中的<modules></modules>标签中的管理的子工程注释掉,并修改<packaging>pom</packaging>为<packaging>jar</packaging>(parent工程的pachaging都是pom),然后install将jar包安装到本地仓库;parent工程打包成功后,将之前注释调的<modules></modules>标签中的注释去掉,修改<packaging>jar</packaging>为<packaging>pom</packaging>,然后在parent工程package打包子工程。

Guess you like

Origin blog.csdn.net/zhangwenchao0814/article/details/108645973