Java – Maven: attach multiple artifacts

I have a maven project that uses some custom jars [not found in any repository] To add them with Maven builds, I use attach - artifact targets in Maven Here are my POM files:

<?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>

My projects using these jars [customjar1. Jar, customjar2. Jar] depend on the POM file [adminbuild] mentioned above

When I execute the MVN clean install command, I get the following error:

[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]

The following is the output of the MVN - version command:

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"

It seems that the way I attach cultural relics is incorrect Shouldn't I attach multiple artifacts to the same POM file? If so, then what Please help.

Solution

Additional artifacts are often used to install other files created by the build, such as webapp classes, jars, documents, or sources

To add files to your Maven repository so that they are available as dependencies, you should use the install - file target

Edit: additional artifacts are identified by the same groupid and artifactid as your main project, but use different classifiers In your configuration, you do not specify a classifier, so no error message will be displayed

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>