gpt4 book ai didi

maven-3 - maven-assembly-plugin 和 maven-jar-plugin 的执行顺序

转载 作者:行者123 更新时间:2023-12-04 03:13:17 25 4
gpt4 key购买 nike

我对 maven-assembly-plugin 和 maven-jar-plugin 的执行顺序有疑问。我想做的是为 pf4j 框架(java 的插件框架)组合一个 uberjar 文件。为此,我需要首先组装所有具有依赖项的代码,然后将 jar 与 list 文件一起打包,该 list 文件具有 pf4j 框架所需的一些特定条目。
在问题 "Changing the order of maven plugin execution"
我在答案中读到绑定(bind)到同一阶段的插件的顺序由 pom.xml 文件中声明的顺序定义。现在我有以下 pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.assembly.test</groupId>
<artifactId>assembly-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>

<plugin.id>some-plugin</plugin.id>
<plugin.class>org.assembly.test.Main</plugin.class>
<plugin.version>0.0.1</plugin.version>
<plugin.provider>Developers</plugin.provider>
<plugin.dependencies />
</properties>

<build>
<plugins>

<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<!-- Assembly Plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filters>
<filter>src/main/assembly/filter.properties</filter>
</filters>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Jar Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.directory}/${project.artifactId}-${project.version}-distro</classesDirectory>
<archive>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

从 pom.xml 文件中应该清楚我想在 maven-assembly-plugin 之后运行 maven-jar-plugin。但相反,我得到以下 Maven 输出:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.assembly.test:assembly-test:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 82, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building assembly-test 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ assembly-test ---
[INFO] Deleting D:\JavaTools\project_btc\projects\assembly-test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ assembly-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ assembly-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to D:\JavaTools\project_btc\projects\assembly-test\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ assembly-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ assembly-test ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ assembly-test ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ assembly-test ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.0.0:single (make-assembly) @ assembly-test ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[ERROR] OS=Windows and the assembly descriptor contains a *nix-specific root-relative-reference (starting with slash) /
[INFO] Copying files to D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT-distro
[WARNING] Assembly file: D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT-distro is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ assembly-test ---
[INFO] Installing D:\JavaTools\project_btc\projects\assembly-test\target\assembly-test-1.0-SNAPSHOT.jar to D:\JavaTools\maven_repository\org\assembly\test\assembly-test\1.0-SNAPSHOT\assembly-test-1.0-SNAPSHOT.jar
[INFO] Installing D:\JavaTools\project_btc\projects\assembly-test\pom.xml to D:\JavaTools\maven_repository\org\assembly\test\assembly-test\1.0-SNAPSHOT\assembly-test-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.376 s
[INFO] Finished at: 2017-04-04T06:04:11+02:00
[INFO] Final Memory: 21M/168M
[INFO] ------------------------------------------------------------------------

现在从输出可以看出 maven-jar-plugin 在 maven-assembly-plugin 之前执行,这不是我想要的。这样一个命令的效果是一个只有 MANIFEST_INF 内容的 jar 文件。

有人可以解释一下我在这里做错了什么吗?

最佳答案

一种可能的解决方案是以这种方式制作 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.assembly.test</groupId>
<artifactId>assembly-test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>

<plugin.id>some-plugin</plugin.id>
<plugin.class>org.assembly.test.Main</plugin.class>
<plugin.version>0.0.1</plugin.version>
<plugin.provider>Developers</plugin.provider>
<plugin.dependencies />
</properties>

<build>
<plugins>

<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>

<!-- Assembly Plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<filters>
<filter>src/main/assembly/filter.properties</filter>
</filters>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- Jar Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classesDirectory>${project.build.directory}/${project.artifactId}-${project.version}-distro</classesDirectory>
<archive>
<manifest>
<mainClass>org.assembly.test.Main</mainClass>
</manifest>
<manifestEntries>
<Plugin-Id>${plugin.id}</Plugin-Id>
<Plugin-Class>${plugin.class}</Plugin-Class>
<Plugin-Version>${plugin.version}</Plugin-Version>
<Plugin-Provider>${plugin.provider}</Plugin-Provider>
<Plugin-Dependencies>${plugin.dependencies}</Plugin-Dependencies>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>default-jar</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

在这里,我将执行部分添加到 maven-jar-plugin 到:
<executions>
<execution>
<id>default-jar</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>

重要的是设置 id默认 jar , 因为在这种情况下默认执行被覆盖并设置 phase验证 在 maven-assembly-plugin 之后执行 maven-jar-plugin。万一 phase设置为 然后 maven-jar-plugin 在 maven-assembly-plugin 之前执行。

关于maven-3 - maven-assembly-plugin 和 maven-jar-plugin 的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43198319/

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