Java &引用;删去“;Maven中生成的默认jar
有一些解决方案可以“禁用”maven jar插件生成的默认jar。然而,由于我的最终工件可能依赖于这个jar(我对maven比较陌生,所以不完全确定它是否真的是这样,但看起来是这样),当我禁用它时,我的构建失败,出现以下错误:Java &引用;删去“;Maven中生成的默认jar,java,maven,maven-jar-plugin,Java,Maven,Maven Jar Plugin,有一些解决方案可以“禁用”maven jar插件生成的默认jar。然而,由于我的最终工件可能依赖于这个jar(我对maven比较陌生,所以不完全确定它是否真的是这样,但看起来是这样),当我禁用它时,我的构建失败,出现以下错误: [ERROR]无法在项目putwb上执行goal org.apache.maven.plugins:maven shade plugin:2.3:shade(build cli):无法创建着色工件,项目主工件不存在。->[帮助1] 否则,它将生成一个空jar以及我正在通过
[ERROR]无法在项目putwb上执行goal org.apache.maven.plugins:maven shade plugin:2.3:shade(build cli):无法创建着色工件,项目主工件不存在。->[帮助1]
否则,它将生成一个空jar以及我正在通过脚本构建的其他jar。有人能建议在构建完成后“删除”默认jar的方法吗?或者,有人能指出我如何在构建成功的情况下禁用它吗
我在下面发布我的pom.xml
的相关部分:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>readme-md</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>README.md</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<!-- Build the CLI version -->
<phase>package</phase>
<id>build-cli</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<!-- Don't include the UI code -->
<filter>
<artifact>*:*</artifact>
<excludes>in/ac/iitk/cse/putwb/ui/**</excludes>
</filter>
</filters>
<finalName>putwb-cli-${project.version}</finalName>
<transformers>
<!-- Don't include images -->
<transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>.png</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>in.ac.iitk.cse.putwb.experiment.PUTExperiment</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
<execution>
<!-- Build the UI version -->
<phase>package</phase>
<id>build-ui</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>putwb-ui-${project.version}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>in.ac.iitk.cse.putwb.ui.PUTWb</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- If I add this to the script, the build fails -->
<!--
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
src/main/resources
真的
org.apache.maven.plugins
maven资源插件
3.0.1
自述文件md
过程资源
复制资源
${project.basedir}
src/main/resources
自述文件
真的
org.apache.maven.plugins
maven阴影插件
2.3
包裹
构建cli
阴凉处
*:*
in/ac/iitk/cse/putwb/ui/**
putwb cli-${project.version}
.png
in.ac.iitk.cse.putwb.experiment.putExperience
包裹
构建用户界面
阴凉处
putwb ui-${project.version}
in.ac.iitk.cse.putwb.ui.putwb
您可以使用ant run插件的删除任务。您可以在生命周期中晚于包阶段的任何阶段执行此插件。(因为它将在包阶段再次创建。请检查哪一个更适合您。)执行您选择作为此插件阶段的maven命令(如选择验证阶段,则执行mvn verify)
org.apache.maven.plugins
感谢@markthegrea指向了正确的文件夹。这对我很有效,但您必须将${project.build.outputDirectory}更改为${project.build.directory},outputDirectory是“目标/类”。看见找到并删除文件时会有一个日志。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<delete file="${project.build.directory}/YourJarName.jar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>