【发布时间】:2018-02-08 15:01:36
【问题描述】:
我有一个 Maven 多模块项目结构。 我想通过在父项目的 pom 中声明来使用 maven-antrun-plugin 构建子项目的 jar。
这是我的父母-pom:
<groupId>com.package.abc</groupId>
<artifactId>parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>concat-build-classpath</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar destfile="${project.build.directory}/${project.build.finalName}.jar"
basedir="src/main">
<manifest>
<attribute name="Main-Class" value="com.package.abc.Application" />
</manifest>
</jar>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>never</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build></project>
这是我的子项目的 pom:
<modelVersion>4.0.0</modelVersion>
<artifactId>sample-project</artifactId>
<parent>
<groupId>com.package.abc</groupId>
<artifactId>parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<finalName>sample-project</finalName>
</build></project>
当我构建子项目时,它显示错误为:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-install) on project sample-project: The packaging for this project did not assign a file to the build artifact -> [Help 1]
【问题讨论】:
-
你为什么使用 maven-antrun-plugin?不遵守约定,让 Maven 完成工作?你想解决什么样的问题?不要在父 pom 中使用插件。你在某处有你项目的完整示例吗(比如 github 等?)
-
@khmarbaise 在创建子项目的 jar(即本示例中的示例项目)时,我想编辑其清单文件的类路径属性。 class-path 属性列出了所有必需的依赖 jar。我想在一些 jar 名称前面加上“folder1/”,一些在前面加上“folder2/”。为此,我正在使用 maven-antrun-plugin。我希望在许多项目中实现这一点。因此,我创建了一个父项目(即本例中的 parent-pom 项目)并在其 pom 中添加了 antrun 插件,所有项目现在都引用了这个 parent-pom。