maven指定多构建源

问题背景:有时候,需要指定一个通用依赖,供其他模块引用。但是,我们又不想多创建一个项目,那么只能另外指定一套打包规则。

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dsc.xueyan</groupId>
    <artifactId>hello.test</artifactId>
    <version>${deploy.type}-1.4.19-SNAPSHOT</version>


    <packaging>jar</packaging>

    <name>dsctest</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>


    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.8</version>
            <optional>true</optional>
        </dependency>


        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.10.1</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

    <build>
        <!--        指定目录,在编译时会构建该路径下的源码,路径是相对与当前路径的-->
        <!--        ${project.basedir}可以获得当前文件在当前所在目录-->
        <sourceDirectory>${project.basedir}/../src/main/java/cloud/xueyan/day13</sourceDirectory>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <!--                plugin也有很多个目标,每个目标具有不同的配置,executions就是设定plugin的目标。-->
                <executions>
                    <execution>
                        <!--此执行的标识符,用于在构建期间标识-->
                        <id>server</id>
                        <!--goals元素代表插件的目标 插件是你前面artifactId中定义好的 goals相当于该插件中的一个功能 该功能将在phase绑定的生命周期阶段执行-->
                        <goals>
                            <goal>jar</goal>
                        </goals>
                        <!-- phase元素代表的是将goals指定的执行目标与指定的生命周期进行绑定-->
                        <phase>package</phase>
                        <configuration>
                            <classifier></classifier>
                            <includes>
                                <!--指定文件列表,该列表就会被插件执行,这个目录下的会被打包成jar-->
                                <include>**/day13/**</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles><!--maven的环境配置-->
        <profile>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <id>beta</id>
            <properties>
                <deploy.type>beta</deploy.type>
            </properties>
        </profile>
        <profile>
<!--            <activation>-->
<!--                <activeByDefault>true</activeByDefault>-->
<!--            </activation>-->
            <id>dev</id>
            <properties>
                <deploy.type>dev</deploy.type>
            </properties>
        </profile>
    </profiles>

</project>

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值