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

2016-08-17 14:18:31 +08:00
 flamhaze5946

在一个工程中我想使用 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>
2178 次点击
所在节点    Java
2 条回复
zhaoace
2016-08-18 09:46:02 +08:00
你是需要一次调用全部做掉么? 如果不是的话我记得 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
2019-02-21 12:53:45 +08:00
@zhaoace 非常感谢, 我之后就是用了两个 Profile

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/299883

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX