Disable distributionManagement in Maven POM

Kurai Bankusu picture Kurai Bankusu · Sep 1, 2016 · Viewed 7.1k times · Source

I am trying to run a mvn deploy goal with maven on my Liferay portlet but am getting the following error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.
2:deploy (default-deploy) on project MyPortlet: Deployment failed: repository eleme
nt was not specified in the POM inside distributionManagement element or in -Dal
tDeploymentRepository=id::layout::url parameter -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on pro
ject RiskID: Deployment failed: repository element was not specified in the POM
inside distributionManagement element or in -DaltDeploymentRepository=id::layout

I understand this error will return if you don't include the <distributionManagement /> tag in the pom.xml, however I don't wish to package this to a remote location and would like to instead deploy to my local tomcat instance; can this be configured?

Answer

A_Di-Matteo picture A_Di-Matteo · Sep 1, 2016

The error is not about dependencyManagement but rather distributionManagement

Deployment failed: repository eleme nt was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter

The alternative (if you don't want to place it in your pom.xml file) is also provided by using the altDeploymentRepository option:

Specifies an alternative repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ). Format: id::layout::url

The first element, the id, must have a matching with a server defined in your settings.xml file (where you specify the credentials to use for the specific server).

The layour and the url are then specific to the target repository.

You can then invoke the command as:

mvn deploy -DaltDeploymentRepository=test:Maven2:http://somewhere:someport

Where test is the id of a server element in your Maven settings

<servers>
    <server>
      <id>test</id>
      <username>my_login</username>
      <password>my_password</password>
    </server>
</servers>

Update
Based on latest clarifications (via comments and edits), here some important points:

  • The Maven deploy phase is meant for

    done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

  • Hence, in your case you don't need to use the deploy phase nor the maven-deploy-plugin.
  • Since Tomcat is the target server, you then need to use the tomcat7-maven-plugin

Here are few instructions:

Configure your pom.xml
Add to your pom.xml the following:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <url>http://localhost:8080/manager/text</url>
        <server>tomcat8</server>
        <path>/${project.build.finalName}</path>
    </configuration>
</plugin>

Configure your settings.xml
Add to your Maven settings.xml the following in the servers section:

<server>
    <username>maven</username>
    <password>maven</password>
    <id>tomcat8</id>
</server>

Note the matching tomcat8 id between the settings and the plugin configuration above, server element.

Configure Tomcat for deploy
In the tomcat conf folder, configure the tomcat-users.xml file:

  <role rolename="manager-script"/>
  <user username="maven" password="maven" roles="manager-gui,manager-script"/>

note the credentials matching with what we actually specified in the Maven settings.

Try it
Then from the command line you can finally invoke:

mvn tomcat7:deploy

If you don't want to configure settings.xml nor pom.xml, you then need to pass several parameters via command line as following:

mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy \ 
      -Durl=http://localhost:8080/manager/text \
      -Dusername=maven -Dpassword=maven

Note: \ and newlines added for readibility

Check full list of options on the official documentation of its deploy goal.