V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
flamhaze5946
V2EX  ›  Java

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

  •  
  •   flamhaze5946 · Aug 17, 2016 · 3059 views
    This topic created in 3554 days ago, the information mentioned may be changed or developed.

    在一个工程中我想使用 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 replies    2019-02-21 12:53:45 +08:00
    zhaoace
        1
    zhaoace  
       Aug 18, 2016   ❤️ 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
       Feb 21, 2019
    @zhaoace 非常感谢, 我之后就是用了两个 Profile
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2564 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 16:07 · PVG 00:07 · LAX 09:07 · JFK 12:07
    ♥ Do have faith in what you're doing.