gpt4 book ai didi

java - Maven: assembly-plugin 根本没有运行

转载 作者:搜寻专家 更新时间:2023-11-01 01:04:09 25 4
gpt4 key购买 nike

我是 Maven 的新手,之前尝试学习过几次,但我认为没有 Maven 会更好。现在,(不)幸运的是,我必须在我想贡献的项目中使用 Maven。我现在的问题是关于包装。我想生成一个包含所有依赖项的自包含(又名“胖”)jar,一位使用 Maven 的同事帮助我处理了 pom 文件。

我检查了他的 pom 文件,以及 SO 上的示例。 xml 看起来合法,但插件根本没有运行。请注意,我没有收到任何错误,一切正常,除了我没有收到“fatjar”。任何想法可能是这个问题的原因?

下面是 pom.xml 的相关部分。关于 <configuration> 的定位,我看到了相互矛盾的代码示例和 <executions>标签,几乎尝试了我发现的所有变体,但仍然不满意。

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>make-jar-with-dependencies</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>ProjectName</finalName>
<appendAssemblyId>true</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.mydomain.ProjectName</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>

Edit_1 mvn clean package 的控制台输出正如@khmarbaise 所问

[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ myproject ---
[INFO] Deleting /home/user/workspace/project/target
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myproject ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 41 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myproject ---
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 292 source files to /home/user/workspace/project/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ myproject ---
[debug] execute contextualize
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/user/workspace/project/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ myproject ---
[INFO] No tests to run.
[INFO] Surefire report directory: /home/user/workspace/project/target/surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ myproject ---
[INFO] Building jar: /home/user/workspace/project/target/myproject-2.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.210s
[INFO] Finished at: Thu Jun 07 11:45:14 CEST 2012
[INFO] Final Memory: 18M/184M
[INFO] ------------------------------------------------------------------------

最佳答案

我建议使用 maven-shade-plugin 创建一个 uberjar ,因为它的意图正是这个目的。您也可以使用 maven-assembly-plugin 来做到这一点。

所以在查看了您的 pom 之后,我明白了问题所在。首先,您在 pluginManagement block 中定义了 maven-assembly-plugin,它将NOT 执行插件此外,您已将 maven-assembly-plugin 单独定义为一个依赖项,这是多余的。这意味着只需从您的 pom 中删除以下内容:

<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<type>maven-plugin</type>
</dependency>

您应该像这样定义 maven-assembler-plugin:

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
...all your configuration here..
</plugin>
</plugins>
</build>

此外,我已经看到许多应该由存储库管理器处理的存储库定义。关于您的 pom 中的存储库,我可以推荐阅读 sonatype information此外,您应该考虑其他人将使用代理等背后的项目,而不是他必须更改您的 pom 才能让我工作或无法使用它,因为您在他无法访问的 pom 中定义了存储库。

关于java - Maven: assembly-plugin 根本没有运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10929199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com