美文网首页部署maven
maven多模块打包

maven多模块打包

作者: virtual灬zzZ | 来源:发表于2022-03-16 18:35 被阅读0次
  • 父工程:

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

    <!-- 环境信息 -->
    <profiles>
        <!-- 标机开发环境 -->
        <profile>
            <id>dev</id>
            <properties>
                <activeProfile>dev</activeProfile>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
        <!-- 测试环境 -->
        <profile>
            <id>test</id>
            <properties>
                <activeProfile>test</activeProfile>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <!-- 生产环境 -->
        <profile>
            <id>product</id>
            <properties>
                <activeProfile>prod</activeProfile>
            </properties>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
        </profile>
    </profiles>
  • 公共模块啥都不加

  • 其余模块

<!--打包-->
    <build>
        <resources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>${maven.resources.plugin.version}</version>
                <configuration>
                    <encoding>${encoding}</encoding>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中-->
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

之后点击idea由上方,选择root,clean、package就行了,公共模块另外自定install到maven仓库中,profile出来的原因是在父工程中配置了的(这里其实也可以改)。


以上只是全部模块打包的形式,如果仅仅只需要打包一个模块,到项目路径,执行以下这句命令就行:
clean package -pl module_name -am

参数详解:
-am, --also-make 同时构建所列模块的依赖模块。必须和-pl同时使用。如 mvn -pl test -am ,将同时构建test的依赖模块。

-pl, --projects <arg> 构建指定的模块,模块间用逗号分隔。可以用来切割大型maven项目,达到急速构建的目的。

参考:
SpringBoot+Maven 多模块项目的构建、运行、打包实战
Maven 多模块项目打包某一模块

相关文章

网友评论

    本文标题:maven多模块打包

    本文链接:https://www.haomeiwen.com/subject/syzphltx.html