V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
flamhaze5946
V2EX  ›  Java

有个比较奇怪的 maven 需求想问~

  •  
  •   flamhaze5946 · 2016-08-17 14:18:31 +08:00 · 2145 次点击
    这是一个创建于 2781 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在一个工程中我想使用 maven-jar-plugin 的<includes>标签只打包我想要放出的 api 接口, 用于打包注释的 maven-source-plugin 也一样.

    但是 springboot 一键打包是个 repackage 过程, 只会根据 maven-jar-plugin 打好的包重新进行打包, 这样就导致部署的时候内容缺失.

    我想问下要怎么才能使 maven-jar-plugin 的<includes>标签和 springboot 一键打包共存呢, 谢谢.

    以下是 pom 的样例:

    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <excludes>
                            <exclude>**/*.properties</exclude>
                        </excludes>
                        <includes>
                            <include>service/api/**</include>
                        </includes>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <excludes>
                            <exclude>**/*.properties</exclude>
                        </excludes>
    
                        <includes>
                            <include>service/api/**</include>
                        </includes>
                    </configuration>
                    <executions>
                        <execution>
                            <id>attach-sources</id>
                            <phase>verify</phase><!--  要绑定到的生命周期的阶段 在 verify 之后, install 之前执行下面指定的 goal -->
                            <goals>
                                <goal>jar-no-fork</goal><!-- 类似执行 mvn source:jar -->
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <mainClass>ServiceClass</mainClass>
                        <layout>ZIP</layout>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
    
    2 条回复    2019-02-21 12:53:45 +08:00
    zhaoace
        1
    zhaoace  
       2016-08-18 09:46:02 +08:00   ❤️ 1
    你是需要一次调用全部做掉么? 如果不是的话我记得 maven 可以分开写两个 Profile 。 写起来会麻烦点。
    大体上就是 profile1 只用来打包 plugin, profile2 只用来做 spring-boot.

    思路上不是配置两个 plugin 之间怎么互相包含或者不包含,而是区分 profile ,不同 profile 的 plugin 进行不同的设置。

    可以参考
    http://maven.apache.org/guides/introduction/introduction-to-profiles.html
    http://haohaoxuexi.iteye.com/blog/1900568


    Sorry maven 不用很久了,没法直接上 code 了。 :)
    flamhaze5946
        2
    flamhaze5946  
    OP
       2019-02-21 12:53:45 +08:00
    @zhaoace 非常感谢, 我之后就是用了两个 Profile
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2757 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:17 · PVG 20:17 · LAX 05:17 · JFK 08:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.