Deploying multiple files in single pom

orepor picture orepor · Nov 7, 2016 · Viewed 10k times · Source

I have a pom which gets some zip, unpacks and deploys the 5 artifacts (jar + pom) that are inside.

It looks something like:

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>deploy-api-jar</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy-file</goal>
                        </goals>
                        <configuration>
                            <file>target/xxx.jar</file>
                            <pomFile>target/xxx/pom.xml</pomFile>
                            <sources>target/xxx-sources.jar</sources>
                            <repositoryId>${nexus-repository-id}</repositoryId>
                            <url>http://${nexus.deploy.server}/${nexus-repository-path}</url>
                        </configuration>
                    </execution>

So I have 5 executions for 5 different artifacts.

It works for the first artifact but then it fails because it tries to upload this again:

[INFO] Uploading: http://www.zzz.com:8081/nexus/content/repositories/mobile-r/xxx/server/deployall/8.1.17/deployall-8.1.17-dependencies.dot

And it fails with 400 BadRequest because depedencies.dot 8.1.17 is already deployed.

Why does it try and upload the depedencies.dot between each artifact? can I disable it?

Answer

blackbuild picture blackbuild · Nov 7, 2016

Edit: answer missed the point

It fails because Maven and thus your nexus only allows one artifact for a given set of coordinates.

So, if you want to deploy them all to the same coordinates, you need to give them different classifiers.

What you want to do is a highly irregular use of a build script. Maven assumes that all artifacts from a single POM have the same coordinates (but different classifiers). If you want that, you can attach the artifacts to the project and upload them using the normal deploy:deploytask in the lifecycle. You can use the build-helper-maven-plugin for that:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>1.12</version>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>file1</file>
            <type>extension of your file</type>
            <classifier>x</classifier>
          </artifact>
          <artifact>
            <file>file2</file>
            <type>extension of your file</type>
            <classifier>y</classifier>
          </artifact>
          ...
          </artifacts>
        </configuration>
      </execution>
    </executions>
  </plugin>

But since you want to upload 5 disjunct artifacts, a POM is not what you want, use a bash script for the upload instead (calling mvn deploy:deploy-file multiple times).