英文:
maven-shade-plugin output with shadedArtifactAttached false overwritten by install
问题
我遇到了使用maven-shade-plugin创建的jar文件部署的问题。它曾经可以正常工作,但现在停止工作了。根据我的研究,问题似乎是安装步骤正在覆盖shaded jar。
如果我使用以下设置:
<shadedArtifactAttached>true</shadedArtifactAttached>
它会为我创建一个fat jar,但如果我将其更改为:
<shadedArtifactAttached>false</shadedArtifactAttached>
安装/部署将删除依赖项和主类的清单条目。
我不想使用"true"设置,因为文件重命名将破坏所有依赖于通过cURL部署的通用脚本的工具。
所以,当我运行以下命令时:
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade
我得到了正确的文件:ontology-merger-0.3.31.jar
(大文件)和original-ontology-merger-0.3.31
(小文件)。
当我运行以下命令时:
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade install
安装步骤将破坏shaded jar。我认为这是因为它在其上运行了maven-jar-plugin
,尽管我在pom.xml
中没有提到maven-jar-plugin
。我不知道如何关闭它。
日志中的重要部分:
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar with C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31-shaded.jar
[INFO] Dependency-reduced POM written at: C:\dev\allotrope\source\ontology-qa-tools\merger\dependency-reduced-pom.xml
...
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ontology-merger --- [INFO] Building jar: C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar
...
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ontology-merger --- [INFO] Installing C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar to C:\Users\User\.m2\repository\com\osthus\ontology-merger\0.3.31\ontology-merger-0.3.31.jar
...
我的pom.xml
中的部分如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<!-- 其他配置 -->
</configuration>
</plugin>
我尝试修复的各种尝试位于这个分支:
https://gitlab.com/allotrope-open-source/ontology-qa-tools/-/tree/deployment-test
pom.xml文件的路径:
https://gitlab.com/allotrope-open-source/ontology-qa-tools/-/blob/deployment-test/merger/pom.xml
一些历史记录:
我的部署曾经在多年内毫无问题地运行,但最近已经中断,我上个月通过以下方式修复:
和
在pom.xml
文件中添加了一些样板,并将
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean deploy
更改为
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade deploy
感谢您的时间。
英文:
I am having a problem with deploying jar files created by the maven-shade-plugin. It used to work, but it has stopped working. From my research the problem seems to be that the install step is overwriting the shaded jar.
If I use the following setting:
<shadedArtifactAttached>true</shadedArtifactAttached>
It will create a fat jar for me, but If I change that to
<shadedArtifactAttached>false</shadedArtifactAttached>
installing/deploying will remove the dependencies and the manifest entry for the main class.
I don't want to use the "true" setting, because the file rename will break all my tooling that depends on a generic script that will a deployed artifact via cURL.
So, when I run
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade
I get the correct files: ontology-merger-0.3.31.jar
(big file) and original-ontology-merger-0.3.31
(small file)
when I run
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade install
the install step will trash the shaded jar. I am assuming that this happens because it's running the maven-jar-plugin
over it, although I don't mention the maven-jar-plugin
anywhere in my pom.xml
. I have no idea how to switch this off.
Important bits from the log:
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar with C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31-shaded.jar
[INFO] Dependency-reduced POM written at: C:\dev\allotrope\source\ontology-qa-tools\merger\dependency-reduced-pom.xml
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ontology-merger --- [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ ontology-merger --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ontology-merger --- [INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 30 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ ontology-merger --- [INFO] No sources to compile [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ontology-merger --- [INFO] Skipping execution of surefire because it has already been run for this configuration [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ ontology-merger --- [INFO] Building jar: C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ ontology-merger --- [INFO] Installing C:\dev\allotrope\source\ontology-qa-tools\merger\target\ontology-merger-0.3.31.jar to C:\Users\User\.m2\repository\com\osthus\ontology-merger\0.3.31\ontology-merger-0.3.31.jar
[INFO] Installing C:\dev\allotrope\source\ontology-qa-tools\merger\dependency-reduced-pom.xml to C:\Users\User\.m2\repository\com\osthus\ontology-merger\0.3.31\ontology-merger-0.3.31.pom
The section in my pom.xml
currently looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.osthus.ontology_merger.MergerMain</mainClass>
<manifestEntries>
<Main-Class>com.osthus.ontology_merger.MergerMain</Main-Class>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
<addHeader>false</addHeader>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<!-- Some jars are signed but shading breaks that. Don't include
signing files. -->
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
My various fix attempts are in this branch:
https://gitlab.com/allotrope-open-source/ontology-qa-tools/-/tree/deployment-test
Path to the pom.xml:
https://gitlab.com/allotrope-open-source/ontology-qa-tools/-/blob/deployment-test/merger/pom.xml
A bit of history:
My deployment that had been working for years without a hitch already broke recently and I fixed it last month via
and
where I had to add some boilerplate to the pom.xml
files and change
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean deploy
to
$ mvn -s ../.m2/settings.xml --batch-mode --errors --fail-at-end --show-version clean package shade:shade deploy
Thanks for your time
答案1
得分: 0
我已经找到了一个解决方案。将以下内容添加到 pom-xml
文件中:
<plugin>
<groupId>maven</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
</plugin>
这将把 maven-jar-plugin
的执行从 install
阶段移动到 package
阶段,因此它将不再覆盖 maven-shade-plugin
的输出。然后可以通过以下方式进行部署:
mvn clean package shade:shade deploy
英文:
I have found a solution. Add this to the pom-xml
:
<plugin>
<groupId>maven</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
</plugin>
This will shift the execution of the maven-jar-plugin
from the install
phase to the package
phase, so it will no longer destroy the output of the maven-shade-plugin
. Deployment can then be done by calling:
mvn clean package shade:shade deploy
专注分享java语言的经验与见解,让所有开发者获益!
评论