Maven profile配置下jar包资源文件排除规则不生效如何解决?
解决方案
- 确认Profile已激活
打开IDEA右侧Maven面板,展开「Profiles」分类,勾选你配置的对应id的profile选项,修改pom.xml后必须点击Maven面板的刷新按钮同步配置。如果使用命令行构建,需要添加-P参数指定激活的profile,比如mvn clean package -Pprofile。 - 优先使用maven-jar-plugin配置排除规则
如果直接在profile的节点配置排除不生效,大概率是全局 下的资源配置和profile内的配置产生了冲突,推荐直接在打jar包阶段配置排除规则,优先级更高不会冲突,示例配置如下:
<profiles> <profile> <id>profile</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.2.2</version> <configuration> <excludes> <exclude>**/abc.txt</exclude> </excludes> </configuration> </plugin> </plugins> </build> </profile> </profiles>
如果还是要使用
<profiles> <profile> <id>profile</id> <build> <resources> <resource> <directory>${project.basedir}/src/main/resources</directory> <excludes> <exclude>**/abc.txt</exclude> </excludes> <filtering>true</filtering> </resource> </resources> </build> </profile> </profiles>
内容的提问来源于stack exchange,提问作者bruno grznar
相关产品推荐
相关产品推荐

