我有一个使用一些自定义 jars [未在任何存储库中找到] 的 maven 项目。为了将它们与 Maven 构建一起添加,我在 maven 中使用了 attach-artifact 目标。以下是我的 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>com.maximus</groupId>
<artifactId>adminbuild</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>adminbuild</name>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<outputDirectory>target</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${basedir}/../../resources/dependencies/java/customjar1.jar</file>
<type>jar</type>
</artifact>
<artifact>
<file>${basedir}/../../resources/dependencies/java/customjar2.jar</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我的项目使用这些 jars [customjar1.jar, customjar2.jar] 依赖于上述 pom 文件 [adminbuild]。
当我执行 mvn clean install
命令时,出现以下错误:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project adminbuild: The artifact with same type and classifier: jar:null is used more than once. -> [Help 1]
以下是mvn -version
命令的输出:
Apache Maven 3.0.3 (r1075438; 2011-02-28 23:01:09+0530)
Maven home: C:\maven
Java version: 1.6.0_26, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.6.0_26\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
似乎我附加工件的方式不正确。我不应该在同一个 pom 文件中附加多个工件吗?如果是,那么如何。请帮忙。
最佳答案
附加的工件通常用于安装由您的构建创建的附加文件,例如 web 应用程序的类 jar、文档或源代码。
要将文件添加到您的 maven 存储库以便它们可以作为依赖项使用,您应该使用 install-file目标。
编辑:附加的工件由与您的主项目相同的 groupId 和 artifactId 标识,但具有不同的分类器。在您的配置中,您没有指定分类器,因此出现错误消息。
关于java - Maven : Attaching multiple artifacts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8239627/