0

I'm using the maven-deploy-plugin to deploy into Nexus an artifact generated by a task of maven-antrun-plugin at the end of my build. The Ant task simply creates a file .sh of the assembled archive built by Maven.

I had to include maven-deploy-plugin because otherwise the .sh is not uploaded into Nexus and it's completely ignored by the lifecycle of the build.

This is the plugin configuration I've tried:

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>3.0.0-M1</version>
    <configuration>
        <skip>false</skip>
    </configuration>
    <executions>
        <execution>
            <id>deploy-sh</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <skip>false</skip>
                <file>${project.build.directory}/${project.artifactId}-${project.version}-autoinstaller.sh</file>
                <repositoryId>myrepo</repositoryId>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <version>${project.version}</version>
            </configuration>
        </execution>
    </executions>
</plugin>

I run the Maven build with mvn clean deploy goals, but it fails with the following error:

[INFO] --- maven-deploy-plugin:3.0.0-M1:deploy-file (deploy-sh) @ MyApplication ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  04:11 min
[INFO] Finished at: 2020-05-01T19:07:40+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file (deploy-sh) on project MyApplication: The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid -> [Help 1]

The parameters 'url' for goal org.apache.maven.plugins:maven-deploy-plugin:3.0.0-M1:deploy-file are missing or invalid

Yes, this occurs because there's not the <url> tag in the section, so it's a mandatory parameter.

But why the <distributionManagement> is completely ignored? I also have a distributionManagement configured for myrepo repository, so urls are configured there.

What I have to do to make it work within the distributionManagement for snapshots and releases?

Alessandro C
  • 3,310
  • 9
  • 46
  • 82
  • I would suggest to use [buildhelper-maven-plugin](https://www.mojohaus.org/build-helper-maven-plugin/plugin-info.html) and attach the artifact to your build is much easier. for example via `attach-artifact`? – khmarbaise May 01 '20 at 18:33
  • @khmarbaise I have found the solution with `` of `maven-antrun-plugin`, as described in the answer that I posted below. By the way, the `attach-artifact` of `buildhelper-maven-plugin` works in the package phase, so it's not useful for my task (I'm in the install phase) – Alessandro C May 01 '20 at 18:58
  • You can bind a plugin to any phase you like....and why not package phase? Can you explain `he Ant task simply creates a file .sh of the assembled archive built by Maven.` more in detail? – khmarbaise May 01 '20 at 19:04
  • As I wrote, I needed to deploy to Nexus a file created by an Ant task which is executed ay the very end of the build, when all files are already created by the build. – Alessandro C May 04 '20 at 09:44

1 Answers1

0

Following this answer, I found the following solution:

  1. I have removed completely the maven-deploy-plugin
  2. I have added <attachartifact> ant task in the maven-antrun-plugin

In this way, the file produced by the Ant run plugin is correctly deployed to Nexus, as described here:

AttachArtifact Task

This task will attatch an artifact to the current Maven project. This is can be used to install and deploy an artifact generated by the Ant tasks.

Community
  • 1
  • 1
Alessandro C
  • 3,310
  • 9
  • 46
  • 82