Maven Install Plugin安装Deb包重复覆盖 求两种实现方案
Maven Install Plugin处理Deb包的两种解决方案
从执行日志可以看到,两个Deb包被安装到了同一个路径project-1.4.0.deb,出现覆盖问题——这是因为jdeb生成的Deb构件默认被附加为项目构件,但未指定分类器,导致Maven Install插件使用相同文件名进行安装。以下是两种符合需求的解决方法:
方案1:忽略Deb包,仅安装Jar和Pom文件
方法1.1:配置Install插件指定安装构件
直接在maven-install-plugin中明确定义需要安装的构件,排除Deb文件:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>${version.maven-install}</version> <configuration> <createChecksum>true</createChecksum> <installations> <!-- 安装主Jar包 --> <installation> <file>${project.build.directory}/${project.build.finalName}.jar</file> <artifact> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>jar</packaging> </artifact> </installation> <!-- 安装Pom文件 --> <installation> <file>${project.file}</file> <artifact> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>pom</packaging> </artifact> </installation> <!-- 安装Javadoc Jar包 --> <installation> <file>${project.build.directory}/${project.build.finalName}-javadoc.jar</file> <artifact> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>jar</packaging> <classifier>javadoc</classifier> </artifact> </installation> </installations> </configuration> </plugin>
方法1.2:配置jdeb不附加Deb构件
在每个jdeb的执行配置中添加<attach>false</attach>,让Maven不将Deb文件视为项目构件,Install插件自然会忽略它们:
<execution> <id>liblinuxjava</id> <phase>package</phase> <goals> <goal>jdeb</goal> </goals> <configuration> <attach>false</attach> <deb>${project.basedir}/target/liblinuxjava-${project.version}_all.deb</deb> <!-- 其余配置保持不变 --> </configuration> </execution> <execution> <id>libwinjava</id> <phase>package</phase> <goals> <goal>jdeb</goal> </goals> <configuration> <attach>false</attach> <deb>${project.basedir}/target/libwinjava-${project.version}_all.deb</deb> <!-- 其余配置保持不变 --> </configuration> </execution>
方案2:安装两个独立的Deb包(保留Jar和Pom)
给每个Deb构件添加分类器(classifier),让Install插件用不同的文件名区分两个Deb包:
<execution> <id>liblinuxjava</id> <phase>package</phase> <goals> <goal>jdeb</goal> </goals> <configuration> <classifier>linux</classifier> <deb>${project.basedir}/target/liblinuxjava-${project.version}_all.deb</deb> <!-- 其余配置保持不变 --> </configuration> </execution> <execution> <id>libwinjava</id> <phase>package</phase> <goals> <goal>jdeb</goal> </goals> <configuration> <classifier>win</classifier> <deb>${project.basedir}/target/libwinjava-${project.version}_all.deb</deb> <!-- 其余配置保持不变 --> </configuration> </execution>
配置完成后,Install插件会将两个Deb包分别安装为:
/home/me/.m2/repository/my/test/project/1.4.0/project-1.4.0-linux.deb/home/me/.m2/repository/my/test/project/1.4.0/project-1.4.0-win.deb
同时Jar和Pom文件会正常保留,不会被覆盖。
内容的提问来源于stack exchange,提问作者Michael Linker
相关产品推荐
相关产品推荐

