maven打包去除dependency-reduced-pom.xml文件

标签 #maven 场景 工作 时间 2023年2月14日17:58:09 一、问题描述 每次打包的时候,项目目录会多出一个莫名的文件dependency-reduced-pom.xml 二、导致原因 maven打包插件maven-shade-plugin打包时自动生成,createDependencyReducedPom默认为true。 dependency-reduced-pom.xml 删除了已经在你的着色 jar 中的传递依赖项。这可以防止消费者两次拉他们,从而避免无用的重复。 三、解决方案 添加以下配置 <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> </configuration> 如: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>3.1.1</version> <configuration> <createDependencyReducedPom>false</createDependencyReducedPom> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <artifactSet> <excludes> <exclude>org.slf4j:*</exclude> <exclude>log4j:*</exclude> <exclude>ch.qos.logback:*</exclude> <exclude>com.google.code.findbugs:jsr305</exclude> </excludes> </artifactSet> <filters> <filter> <!-- Do not copy the signatures in the META-INF folder. Otherwise, this might cause SecurityExceptions when using the JAR. --> <artifact>*:*</artifact> <excludes> <exclude>META-INF/*.SF</exclude> <exclude>META-INF/*.DSA</exclude> <exclude>META-INF/*.RSA</exclude> </excludes> </filter> </filters> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <!-- Replace this with the main class of your job --> <mainClass>my.programs.main.clazz</mainClass> </transformer> <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/> </transformers> </configuration> </execution> </executions> </plugin>

2024年11月9日 · 1 分钟

关于maven项目的配置文件

把项目的配置文件按运行环境做一下区分,比如开发环境和线上环境使用的使用不同的配置文件,这里我们基于项目的 resoures/ 目录来实现: # resoures 目录 . ├── env │ ├── config.dev.properties │ └── config.prod.properties └── config.properties 我们创建了一个 config.properties 文件来配置项目的常用配置数据,如, kafaka 、 redis 等连接配置等。 然后创建一个 env 子目录,并创建两个环境对应的配置文件,我们希望不同的环境当中使用不同的配置。当然,光是创建这些文件,是无法让文件实现自动按照运行环境自动实现文件匹配的,我们还需要配置 pom.xml 文件: 首先,找到 <build> 配置字段,添加文件路径: <build> <!-- Loading all ${} --> <filters> <filter>src/main/resources/env/config.${env}.properties</filter> </filters> <!-- Map ${} into resources --> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>*.properties</include> </includes> </resource> </resources> <!-- 省略之后若干行 --> </build> 上述代码目的是告诉构建工具,在构建的时候需要加载 resoures 目录的配置文件参与构建,并且使用 ${env} 环境变量来决定具体加载的名称。 因此,我们还需要指定 ${env} 的环境变量配置,在 <profiles> 标签下,移除默认的 <profile> 配置内容,新建两份环境配置 dev 和 prod 的 profile 文件配置: ...

2023年10月15日 · 1 分钟