You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2022/02/24 16:02:22 UTC

[maven-deploy-plugin] branch mvn4 updated: Switch a few core plugins to the new api

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch mvn4
in repository https://gitbox.apache.org/repos/asf/maven-deploy-plugin.git


The following commit(s) were added to refs/heads/mvn4 by this push:
     new ee568ac  Switch a few core plugins to the new api
ee568ac is described below

commit ee568ac7d4de210e85d93899113311bb543c4b0b
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu Feb 24 17:00:56 2022 +0100

    Switch a few core plugins to the new api
---
 pom.xml                                            |  22 +-
 .../maven/plugins/deploy/AbstractDeployMojo.java   |  35 ++--
 .../maven/plugins/deploy/DeployFileMojo.java       | 224 +++++++++++----------
 .../apache/maven/plugins/deploy/DeployMojo.java    | 163 +++++++++------
 .../maven/plugins/deploy/DeployFileMojoTest.java   |  21 +-
 .../plugins/deploy/DeployFileMojoUnitTest.java     |   9 +-
 .../maven/plugins/deploy/DeployMojoTest.java       | 115 ++++-------
 ...tDeployerStub.java => ProjectDeployerStub.java} |  25 +--
 .../maven/plugins/deploy/stubs/ProjectStub.java    | 115 +++++++++++
 9 files changed, 420 insertions(+), 309 deletions(-)

diff --git a/pom.xml b/pom.xml
index a061237..ac1076f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@ under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.maven</groupId>
-      <artifactId>maven-plugin-api</artifactId>
+      <artifactId>maven-core-api</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
     <dependency>
@@ -84,17 +84,17 @@ under the License.
       <artifactId>maven-model</artifactId>
       <version>${mavenVersion}</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-artifact</artifactId>
-      <version>${mavenVersion}</version>
-    </dependency>
+<!--    <dependency>-->
+<!--      <groupId>org.apache.maven</groupId>-->
+<!--      <artifactId>maven-artifact</artifactId>-->
+<!--      <version>${mavenVersion}</version>-->
+<!--    </dependency>-->
     
-    <dependency>
-      <groupId>org.apache.maven.shared</groupId>
-      <artifactId>maven-artifact-transfer</artifactId>
-      <version>2.0.0-SNAPSHOT</version>
-    </dependency>
+<!--    <dependency>-->
+<!--      <groupId>org.apache.maven.shared</groupId>-->
+<!--      <artifactId>maven-artifact-transfer</artifactId>-->
+<!--      <version>2.0.0-SNAPSHOT</version>-->
+<!--    </dependency>-->
     <!-- Upgrade of transitive dependency. -->
     <dependency>
       <groupId>commons-io</groupId>
diff --git a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
index f933e36..5d03ecb 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/AbstractDeployMojo.java
@@ -19,22 +19,23 @@ package org.apache.maven.plugins.deploy;
  * under the License.
  */
 
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.MavenArtifactRepository;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.Mojo;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.RepositoryFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Abstract class for Deploy mojo's.
  */
-public abstract class AbstractDeployMojo
-    extends AbstractMojo
+public abstract class AbstractDeployMojo implements Mojo
 {
 
+    protected Logger logger = LoggerFactory.getLogger( getClass() );
+
     /**
      * Flag whether Maven is currently in online/offline mode.
      */
@@ -51,16 +52,16 @@ public abstract class AbstractDeployMojo
     private int retryFailedDeploymentCount;
 
     @Parameter( defaultValue = "${session}", readonly = true, required = true )
-    private MavenSession session;
+    private Session session;
     
     /* Setters and Getters */
 
     void failIfOffline()
-        throws MojoFailureException
+        throws MojoException
     {
         if ( offline )
         {
-            throw new MojoFailureException( "Cannot deploy artifacts when Maven is in offline mode" );
+            throw new MojoException( "Cannot deploy artifacts when Maven is in offline mode" );
         }
     }
 
@@ -69,13 +70,13 @@ public abstract class AbstractDeployMojo
         return retryFailedDeploymentCount;
     }
 
-    protected ArtifactRepository createDeploymentArtifactRepository( String id, String url )
+    protected RemoteRepository createDeploymentArtifactRepository( String id, String url )
     {
-        return new MavenArtifactRepository( id, url, new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
-                                            new ArtifactRepositoryPolicy() );
+        return getSession().getService( RepositoryFactory.class )
+                .createRemote( id, url );
     }
     
-    protected final MavenSession getSession()
+    protected final Session getSession()
     {
         return session;
     }
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
index 4304421..de87828 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java
@@ -19,6 +19,7 @@ package org.apache.maven.plugins.deploy;
  * under the License.
  */
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -27,38 +28,36 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.Reader;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.regex.Pattern;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Component;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerException;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectBuilder;
+import org.apache.maven.api.services.ProjectBuilderException;
+import org.apache.maven.api.services.ProjectBuilderRequest;
+import org.apache.maven.api.services.ProjectBuilderResult;
+import org.apache.maven.api.services.ProjectBuilderSource;
+import org.apache.maven.api.services.ProjectManager;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
-import org.apache.maven.model.building.ModelBuildingException;
-import org.apache.maven.model.building.ModelSource;
-import org.apache.maven.model.building.StringModelSource;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
-import org.apache.maven.project.ProjectBuilder;
-import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.artifact.ProjectArtifactMetadata;
-import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-import org.apache.maven.shared.transfer.repository.RepositoryManager;
-import org.apache.maven.shared.utils.Os;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
@@ -71,18 +70,21 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
  * 
  * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
  */
-@Mojo( name = "deploy-file", requiresProject = false, threadSafe = true )
+@Mojo( name = "deploy-file", requiresProject = false )
 public class DeployFileMojo
     extends AbstractDeployMojo
 {
     @Component
     private ArtifactDeployer artifactDeployer;
 
+    @Component
+    private ArtifactManager artifactManager;
+
     /**
      * Used for attaching the artifacts to deploy to the project.
      */
     @Component
-    private MavenProjectHelper projectHelper;
+    private ProjectManager projectManager;
 
     /**
      * Used for creating the project to which the artifacts to deploy will be attached.
@@ -90,6 +92,7 @@ public class DeployFileMojo
     @Component
     private ProjectBuilder projectBuilder;
 
+
     /**
      * GroupId of the artifact to be deployed. Retrieved from POM file if specified.
      */
@@ -208,11 +211,8 @@ public class DeployFileMojo
     @Parameter( property = "files" )
     private String files;
 
-    @Component
-    private RepositoryManager repoManager;
-
     void initProperties()
-        throws MojoExecutionException
+        throws MojoException
     {
         if ( pomFile == null )
         {
@@ -233,7 +233,7 @@ public class DeployFileMojo
 
                     if ( pomEntry.matcher( entry.getName() ).matches() )
                     {
-                        getLog().debug( "Using " + entry.getName() + " as pomFile" );
+                        logger.debug( "Using " + entry.getName() + " as pomFile" );
 
                         foundPom = true;
 
@@ -274,7 +274,7 @@ public class DeployFileMojo
 
                 if ( !foundPom )
                 {
-                    getLog().info( "pom.xml not found in " + file.getName() );
+                    logger.info( "pom.xml not found in " + file.getName() );
                 }
             }
             catch ( IOException e )
@@ -308,11 +308,11 @@ public class DeployFileMojo
     }
 
     public void execute()
-        throws MojoExecutionException, MojoFailureException
+        throws MojoException
     {
         if ( uniqueVersion != null )
         {
-            throw new MojoExecutionException( "You are using 'uniqueVersion' which has been removed"
+            throw new MojoException( "You are using 'uniqueVersion' which has been removed"
                 + " from the maven-deploy-plugin. "
                 + "Please see the >>Major Version Upgrade to version 3.0.0<< on the plugin site." );
         }
@@ -321,38 +321,38 @@ public class DeployFileMojo
 
         if ( !file.exists() )
         {
-            throw new MojoExecutionException( file.getPath() + " not found." );
+            throw new MojoException( file.getPath() + " not found." );
         }
 
         initProperties();
 
-        ArtifactRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
+        RemoteRepository deploymentRepository = createDeploymentArtifactRepository( repositoryId, url );
 
         String protocol = deploymentRepository.getProtocol();
 
         if ( StringUtils.isEmpty( protocol ) )
         {
-            throw new MojoExecutionException( "No transfer protocol found." );
+            throw new MojoException( "No transfer protocol found." );
         }
 
-        MavenProject project = createMavenProject();
+        Project project = createMavenProject();
         Artifact artifact = project.getArtifact();
 
-        if ( file.equals( getLocalRepoFile() ) )
+        if ( file.equals( getLocalRepoFile().toFile() ) )
         {
-            throw new MojoFailureException( "Cannot deploy artifact from the local repository: " + file );
+            throw new MojoException( "Cannot deploy artifact from the local repository: " + file );
         }
 
         List<Artifact> deployableArtifacts = new ArrayList<Artifact>();
 
         if ( classifier == null )
         {
-            artifact.setFile( file );
+            artifactManager.setPath( artifact, file.toPath() );
             deployableArtifacts.add( artifact );
         }
         else
         {
-            projectHelper.attachArtifact( project, packaging, classifier, file );
+            projectManager.attachArtifact( project, packaging, classifier, file.toPath() );
         }
 
         // Upload the POM if requested, generating one if need be
@@ -367,50 +367,51 @@ public class DeployFileMojo
             {
                 if ( classifier == null )
                 {
-                    ProjectArtifactMetadata metadata = new ProjectArtifactMetadata( artifact, pom );
-                    artifact.addMetadata( metadata );
+                    Artifact pomArtifact = getSession().createArtifact(
+                            groupId, artifactId, "", version, "pom"
+                    );
+                    artifactManager.setPath( pomArtifact, pom.toPath() );
+                    deployableArtifacts.add( pomArtifact );
                 }
                 else
                 {
-                    artifact.setFile( pom );
+                    artifactManager.setPath( artifact, pom.toPath() );
                     deployableArtifacts.add( artifact );
                 }
             }
         }
 
-        artifact.setRepository( deploymentRepository );
-
         if ( sources != null )
         {
-            projectHelper.attachArtifact( project, "jar", "sources", sources );
+            projectManager.attachArtifact( project, "jar", "sources", sources.toPath() );
         }
 
         if ( javadoc != null )
         {
-            projectHelper.attachArtifact( project, "jar", "javadoc", javadoc );
+            projectManager.attachArtifact( project, "jar", "javadoc", javadoc.toPath() );
         }
 
         if ( files != null )
         {
             if ( types == null )
             {
-                throw new MojoExecutionException( "You must specify 'types' if you specify 'files'" );
+                throw new MojoException( "You must specify 'types' if you specify 'files'" );
             }
             if ( classifiers == null )
             {
-                throw new MojoExecutionException( "You must specify 'classifiers' if you specify 'files'" );
+                throw new MojoException( "You must specify 'classifiers' if you specify 'files'" );
             }
             int filesLength = StringUtils.countMatches( files, "," );
             int typesLength = StringUtils.countMatches( types, "," );
             int classifiersLength = StringUtils.countMatches( classifiers, "," );
             if ( typesLength != filesLength )
             {
-                throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
+                throw new MojoException( "You must specify the same number of entries in 'files' and "
                     + "'types' (respectively " + filesLength + " and " + typesLength + " entries )" );
             }
             if ( classifiersLength != filesLength )
             {
-                throw new MojoExecutionException( "You must specify the same number of entries in 'files' and "
+                throw new MojoException( "You must specify the same number of entries in 'files' and "
                     + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )" );
             }
             int fi = 0;
@@ -437,23 +438,17 @@ public class DeployFileMojo
                 if ( !file.isFile() )
                 {
                     // try relative to the project basedir just in case
-                    file = new File( project.getBasedir(), files.substring( fi, nfi ) );
+                    file = new File( project.getPomPath().getParent().toFile(), files.substring( fi, nfi ) );
                 }
                 if ( file.isFile() )
                 {
-                    if ( StringUtils.isWhitespace( classifiers.substring( ci, nci ) ) )
-                    {
-                        projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(), file );
-                    }
-                    else
-                    {
-                        projectHelper.attachArtifact( project, types.substring( ti, nti ).trim(),
-                                                      classifiers.substring( ci, nci ).trim(), file );
-                    }
+                    String classifier = classifiers.substring( ci, nci ).trim();
+                    String type = types.substring( ti, nti ).trim();
+                    projectManager.attachArtifact( project, type, classifier, file.toPath() );
                 }
                 else
                 {
-                    throw new MojoExecutionException( "Specified side artifact " + file + " does not exist" );
+                    throw new MojoException( "Specified side artifact " + file + " does not exist" );
                 }
                 fi = nfi + 1;
                 ti = nti + 1;
@@ -464,29 +459,25 @@ public class DeployFileMojo
         {
             if ( types != null )
             {
-                throw new MojoExecutionException( "You must specify 'files' if you specify 'types'" );
+                throw new MojoException( "You must specify 'files' if you specify 'types'" );
             }
             if ( classifiers != null )
             {
-                throw new MojoExecutionException( "You must specify 'files' if you specify 'classifiers'" );
+                throw new MojoException( "You must specify 'files' if you specify 'classifiers'" );
             }
         }
 
-        List<Artifact> attachedArtifacts = project.getAttachedArtifacts();
+        Collection<Artifact> attachedArtifacts = projectManager.getAttachedArtifacts( project );
 
-        for ( Artifact attached : attachedArtifacts )
-        {
-            deployableArtifacts.add( attached );
-        }
+        deployableArtifacts.addAll( attachedArtifacts );
 
         try
         {
-            artifactDeployer.deploy( getSession().getProjectBuildingRequest(), deploymentRepository,
-                                     deployableArtifacts );
+            artifactDeployer.deploy( getSession(), deploymentRepository, deployableArtifacts );
         }
         catch ( ArtifactDeployerException e )
         {
-            throw new MojoExecutionException( e.getMessage(), e );
+            throw new MojoException( e.getMessage(), e );
         }
     }
 
@@ -496,36 +487,38 @@ public class DeployFileMojo
      * to attach the artifacts to deploy to.
      * 
      * @return The created Maven project, never <code>null</code>.
-     * @throws MojoExecutionException When the model of the project could not be built.
-     * @throws MojoFailureException When building the project failed.
+     * @throws MojoException When the model of the project could not be built.
      */
-    private MavenProject createMavenProject()
-        throws MojoExecutionException, MojoFailureException
+    private Project createMavenProject()
+        throws MojoException
     {
         if ( groupId == null || artifactId == null || version == null || packaging == null )
         {
-            throw new MojoExecutionException( "The artifact information is incomplete: 'groupId', 'artifactId', "
+            throw new MojoException( "The artifact information is incomplete: 'groupId', 'artifactId', "
                 + "'version' and 'packaging' are required." );
         }
-        ModelSource modelSource =
-            new StringModelSource( "<project>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>" + groupId
-                + "</groupId>" + "<artifactId>" + artifactId + "</artifactId>" + "<version>" + version + "</version>"
-                + "<packaging>" + ( classifier == null ? packaging : "pom" ) + "</packaging>" + "</project>" );
-        DefaultProjectBuildingRequest buildingRequest =
-            new DefaultProjectBuildingRequest( getSession().getProjectBuildingRequest() );
-        buildingRequest.setProcessPlugins( false );
         try
         {
-            return projectBuilder.build( modelSource, buildingRequest ).getProject();
+            String prj = "<project>"
+                    + "<modelVersion>4.0.0</modelVersion>"
+                    + "<groupId>" + groupId + "</groupId>"
+                    + "<artifactId>" + artifactId + "</artifactId>"
+                    + "<version>" + version + "</version>"
+                    + "<packaging>" + ( classifier == null ? packaging : "pom" ) + "</packaging>"
+                    + "</project>";
+            ProjectBuilderResult result = getSession().getService( ProjectBuilder.class )
+                    .build( ProjectBuilderRequest.builder()
+                            .session( getSession() )
+                            .source( new StringSource( prj ) )
+                            .processPlugins( false )
+                            .resolveDependencies( false )
+                            .build() );
+
+            return result.getProject().get();
         }
-        catch ( ProjectBuildingException e )
+        catch ( ProjectBuilderException e )
         {
-            if ( e.getCause() instanceof ModelBuildingException )
-            {
-                throw new MojoExecutionException( "The artifact information is not valid:" + Os.LINE_SEP
-                    + e.getCause().getMessage() );
-            }
-            throw new MojoFailureException( "Unable to create the project.", e );
+            throw new MojoException( "Unable to create the project.", e );
         }
     }
 
@@ -535,16 +528,10 @@ public class DeployFileMojo
      * 
      * @return The absolute path to the artifact when installed, never <code>null</code>.
      */
-    private File getLocalRepoFile()
+    private Path getLocalRepoFile()
     {
-        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
-        coordinate.setGroupId( groupId );
-        coordinate.setArtifactId( artifactId );
-        coordinate.setVersion( version );
-        coordinate.setClassifier( classifier );
-        coordinate.setExtension( packaging );
-        String path = repoManager.getPathForLocalArtifact( getSession().getProjectBuildingRequest(), coordinate );
-        return new File( repoManager.getLocalRepositoryBasedir( getSession().getProjectBuildingRequest() ), path );
+        Artifact artifact = getSession().createArtifact( groupId, artifactId, classifier, version, packaging );
+        return getSession().getPathForLocalArtifact( artifact );
     }
 
     /**
@@ -587,10 +574,10 @@ public class DeployFileMojo
      * 
      * @param pomFile The path of the POM file to parse, must not be <code>null</code>.
      * @return The model from the POM file, never <code>null</code>.
-     * @throws MojoExecutionException If the file doesn't exist of cannot be read.
+     * @throws MojoException If the file doesn't exist of cannot be read.
      */
     Model readModel( File pomFile )
-        throws MojoExecutionException
+        throws MojoException
     {
         Reader reader = null;
         try
@@ -603,15 +590,15 @@ public class DeployFileMojo
         }
         catch ( FileNotFoundException e )
         {
-            throw new MojoExecutionException( "POM not found " + pomFile, e );
+            throw new MojoException( "POM not found " + pomFile, e );
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error reading POM " + pomFile, e );
+            throw new MojoException( "Error reading POM " + pomFile, e );
         }
         catch ( XmlPullParserException e )
         {
-            throw new MojoExecutionException( "Error parsing POM " + pomFile, e );
+            throw new MojoException( "Error parsing POM " + pomFile, e );
         }
         finally
         {
@@ -623,10 +610,10 @@ public class DeployFileMojo
      * Generates a minimal POM from the user-supplied artifact information.
      * 
      * @return The path to the generated POM file, never <code>null</code>.
-     * @throws MojoExecutionException If the generation failed.
+     * @throws MojoException If the generation failed.
      */
     private File generatePomFile()
-        throws MojoExecutionException
+        throws MojoException
     {
         Model model = generateModel();
 
@@ -647,7 +634,7 @@ public class DeployFileMojo
         }
         catch ( IOException e )
         {
-            throw new MojoExecutionException( "Error writing temporary pom file: " + e.getMessage(), e );
+            throw new MojoException( "Error writing temporary pom file: " + e.getMessage(), e );
         }
         finally
         {
@@ -736,4 +723,25 @@ public class DeployFileMojo
         this.classifier = classifier;
     }
 
+    private static class StringSource implements ProjectBuilderSource
+    {
+        private final String prj;
+
+        StringSource( String prj )
+        {
+            this.prj = prj;
+        }
+
+        @Override
+        public InputStream getInputStream() throws IOException
+        {
+            return new ByteArrayInputStream( prj.getBytes( StandardCharsets.UTF_8 ) );
+        }
+
+        @Override
+        public String getLocation()
+        {
+            return null;
+        }
+    }
 }
diff --git a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
index ae26134..f4083ec 100644
--- a/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
+++ b/src/main/java/org/apache/maven/plugins/deploy/DeployMojo.java
@@ -20,26 +20,33 @@ package org.apache.maven.plugins.deploy;
  */
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-
-import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.LifecyclePhase;
-import org.apache.maven.plugins.annotations.Mojo;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-import org.apache.maven.shared.transfer.project.NoFileAssignedException;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployer;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Project;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.annotations.Component;
+import org.apache.maven.api.plugin.annotations.LifecyclePhase;
+import org.apache.maven.api.plugin.annotations.Mojo;
+import org.apache.maven.api.plugin.annotations.Parameter;
+import org.apache.maven.api.services.ArtifactDeployer;
+import org.apache.maven.api.services.ArtifactDeployerRequest;
+import org.apache.maven.api.services.ArtifactManager;
+import org.apache.maven.api.services.ProjectDeployer;
+import org.apache.maven.api.services.ProjectDeployerException;
+import org.apache.maven.api.services.ProjectDeployerRequest;
+import org.apache.maven.api.services.ProjectManager;
+import org.apache.maven.api.services.RepositoryFactory;
+import org.apache.maven.model.DistributionManagement;
+import org.apache.maven.shared.utils.StringUtils;
 
 /**
  * Deploys an artifact to remote repository.
@@ -47,7 +54,7 @@ import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @author <a href="mailto:jdcasey@apache.org">John Casey (refactoring only)</a>
  */
-@Mojo( name = "deploy", defaultPhase = LifecyclePhase.DEPLOY, threadSafe = true )
+@Mojo( name = "deploy", defaultPhase = LifecyclePhase.DEPLOY )
 public class DeployMojo
     extends AbstractDeployMojo
 {
@@ -61,16 +68,16 @@ public class DeployMojo
      */
     private static final AtomicInteger READYPROJECTSCOUNTER = new AtomicInteger();
 
-    private static final List<ProjectDeployerRequest> DEPLOYREQUESTS =
-        Collections.synchronizedList( new ArrayList<ProjectDeployerRequest>() );
+    private static final List<ArtifactDeployerRequest> DEPLOYREQUESTS =
+        Collections.synchronizedList( new ArrayList<>() );
 
     /**
      */
     @Parameter( defaultValue = "${project}", readonly = true, required = true )
-    private MavenProject project;
+    private Project project;
 
     @Parameter( defaultValue = "${reactorProjects}", required = true, readonly = true )
-    private List<MavenProject> reactorProjects;
+    private List<Project> reactorProjects;
 
     /**
      * Whether every project should be deployed during its own deploy-phase or at the end of the multimodule build. If
@@ -97,7 +104,7 @@ public class DeployMojo
      * has been removed because Maven 3 only supports Maven 2 repository layout.
      */
     @Parameter( property = "altDeploymentRepository" )
-    private String altDeploymentRepository;
+    String altDeploymentRepository;
 
     /**
      * The alternative repository to use when the project has a snapshot version.
@@ -143,41 +150,61 @@ public class DeployMojo
     @Component
     private ProjectDeployer projectDeployer;
 
+    @Component
+    private ArtifactManager artifactManager;
+
+    @Component
+    private ArtifactDeployer artifactDeployer;
+
     public void execute()
-        throws MojoExecutionException, MojoFailureException
+        throws MojoException
     {
         boolean addedDeployRequest = false;
+        boolean isSnapshot = artifactManager.isSnapshot( project.getVersion() );
         if ( Boolean.parseBoolean( skip )
-            || ( "releases".equals( skip ) && !ArtifactUtils.isSnapshot( project.getVersion() ) )
-            || ( "snapshots".equals( skip ) && ArtifactUtils.isSnapshot( project.getVersion() ) )
+            || ( "releases".equals( skip ) && !isSnapshot )
+            || ( "snapshots".equals( skip ) && isSnapshot )
         )
         {
-            getLog().info( "Skipping artifact deployment" );
+            logger.info( "Skipping artifact deployment" );
         }
         else
         {
             failIfOffline();
 
+            List<Artifact> deployables = new ArrayList<>();
+
+            deployables.add( project.getArtifact() );
+
+            if ( !"pom".equals( project.getPackaging() ) )
+            {
+                Artifact pomArtifact = getSession().createArtifact(
+                        project.getGroupId(), project.getArtifactId(), "",
+                        project.getVersion(), "pom" );
+                artifactManager.setPath( pomArtifact, project.getPomPath() );
+                deployables.add( pomArtifact );
+            }
+
+            ProjectManager projectManager = getSession().getService( ProjectManager.class );
+            deployables.addAll( projectManager.getAttachedArtifacts( project ) );
+
             // CHECKSTYLE_OFF: LineLength
             // @formatter:off
-            ProjectDeployerRequest pdr = new ProjectDeployerRequest()
-                .setProject( project )
-                .setRetryFailedDeploymentCount( getRetryFailedDeploymentCount() )
-                .setAltReleaseDeploymentRepository( altReleaseDeploymentRepository )
-                .setAltSnapshotDeploymentRepository( altSnapshotDeploymentRepository )
-                .setAltDeploymentRepository( altDeploymentRepository );
+            ArtifactDeployerRequest adr = ArtifactDeployerRequest.builder()
+                .repository( getDeploymentRepository( isSnapshot ) )
+                .artifacts( deployables )
+                .retryFailedDeploymentCount( getRetryFailedDeploymentCount() )
+                .build();
             // @formatter:on
             // CHECKSTYLE_ON: LineLength
 
-            ArtifactRepository repo = getDeploymentRepository( pdr );
-
             if ( !deployAtEnd )
             {
-                deployProject( getSession().getProjectBuildingRequest(), pdr, repo );
+                deployProject( adr );
             }
             else
             {
-                DEPLOYREQUESTS.add( pdr );
+                DEPLOYREQUESTS.add( adr );
                 addedDeployRequest = true;
             }
         }
@@ -189,54 +216,42 @@ public class DeployMojo
             {
                 while ( !DEPLOYREQUESTS.isEmpty() )
                 {
-                    ArtifactRepository repo = getDeploymentRepository( DEPLOYREQUESTS.get( 0 ) );
-
-                    deployProject( getSession().getProjectBuildingRequest(), DEPLOYREQUESTS.remove( 0 ), repo );
+                    deployProject( DEPLOYREQUESTS.remove( 0 ) );
                 }
             }
         }
         else if ( addedDeployRequest )
         {
-            getLog().info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
+            logger.info( "Deploying " + project.getGroupId() + ":" + project.getArtifactId() + ":"
                 + project.getVersion() + " at end" );
         }
     }
 
-    private void deployProject( ProjectBuildingRequest pbr, ProjectDeployerRequest pir, ArtifactRepository repo )
-        throws MojoFailureException, MojoExecutionException
+    private void deployProject( ArtifactDeployerRequest adr )
+        throws MojoException
     {
         try
         {
-            projectDeployer.deploy( pbr, pir, repo );
-        }
-        catch ( NoFileAssignedException e )
-        {
-            throw new MojoExecutionException( "NoFileAssignedException", e );
+            artifactDeployer.deploy( adr );
         }
-        catch ( ArtifactDeployerException e )
+        catch ( ProjectDeployerException e )
         {
-            throw new MojoExecutionException( "ArtifactDeployerException", e );
+            throw new MojoException( "ProjectDeployerException", e );
         }
 
     }
 
-    ArtifactRepository getDeploymentRepository( ProjectDeployerRequest pdr )
-
-        throws MojoExecutionException, MojoFailureException
+    RemoteRepository getDeploymentRepository( boolean isSnapshot )
+        throws MojoException
     {
-        MavenProject project = pdr.getProject();
-        String altDeploymentRepository = pdr.getAltDeploymentRepository();
-        String altReleaseDeploymentRepository = pdr.getAltReleaseDeploymentRepository();
-        String altSnapshotDeploymentRepository = pdr.getAltSnapshotDeploymentRepository();
-
-        ArtifactRepository repo = null;
+        RemoteRepository repo = null;
 
         String altDeploymentRepo;
-        if ( ArtifactUtils.isSnapshot( project.getVersion() ) && altSnapshotDeploymentRepository != null )
+        if ( isSnapshot && altSnapshotDeploymentRepository != null )
         {
             altDeploymentRepo = altSnapshotDeploymentRepository;
         }
-        else if ( !ArtifactUtils.isSnapshot( project.getVersion() ) && altReleaseDeploymentRepository != null )
+        else if ( !isSnapshot && altReleaseDeploymentRepository != null )
         {
             altDeploymentRepo = altReleaseDeploymentRepository;
         }
@@ -247,7 +262,7 @@ public class DeployMojo
 
         if ( altDeploymentRepo != null )
         {
-            getLog().info( "Using alternate deployment repository " + altDeploymentRepo );
+            logger.info( "Using alternate deployment repository " + altDeploymentRepo );
 
             Matcher matcher = ALT_LEGACY_REPO_SYNTAX_PATTERN.matcher( altDeploymentRepo );
 
@@ -259,13 +274,13 @@ public class DeployMojo
 
                 if ( "default".equals( layout ) )
                 {
-                    getLog().warn( "Using legacy syntax for alternative repository. "
+                    logger.warn( "Using legacy syntax for alternative repository. "
                             + "Use \"" + id + "::" + url + "\" instead." );
                     repo = createDeploymentArtifactRepository( id, url );
                 }
                 else
                 {
-                    throw new MojoFailureException( altDeploymentRepo,
+                    throw new MojoException( altDeploymentRepo,
                             "Invalid legacy syntax and layout for repository.",
                             "Invalid legacy syntax and layout for alternative repository. Use \""
                                     + id + "::" + url + "\" instead, and only default layout is supported."
@@ -278,7 +293,7 @@ public class DeployMojo
 
                 if ( !matcher.matches() )
                 {
-                    throw new MojoFailureException( altDeploymentRepo,
+                    throw new MojoException( altDeploymentRepo,
                             "Invalid syntax for repository.",
                             "Invalid syntax for alternative repository. Use \"id::url\"."
                     );
@@ -295,7 +310,25 @@ public class DeployMojo
 
         if ( repo == null )
         {
-            repo = project.getDistributionManagementArtifactRepository();
+            DistributionManagement dm = project.getModel().getDistributionManagement();
+            if ( dm != null )
+            {
+                boolean snapshot = isSnapshot;
+                if ( snapshot && dm.getSnapshotRepository() != null
+                        && StringUtils.isNotEmpty(  dm.getSnapshotRepository().getId() )
+                        && StringUtils.isNotEmpty( dm.getSnapshotRepository().getUrl() ) )
+                {
+                    repo = getSession().getService( RepositoryFactory.class )
+                            .createRemote( dm.getSnapshotRepository() );
+                }
+                else if ( dm.getRepository() != null
+                        && StringUtils.isNotEmpty(  dm.getRepository().getId() )
+                        && StringUtils.isNotEmpty( dm.getRepository().getUrl() )  )
+                {
+                    repo = getSession().getService( RepositoryFactory.class )
+                            .createRemote( dm.getRepository() );
+                }
+            }
         }
 
         if ( repo == null )
@@ -303,7 +336,7 @@ public class DeployMojo
             String msg = "Deployment failed: repository element was not specified in the POM inside"
                 + " distributionManagement element or in -DaltDeploymentRepository=id::url parameter";
 
-            throw new MojoExecutionException( msg );
+            throw new MojoException( msg );
         }
 
         return repo;
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
index 6c7064b..3f7eb14 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoTest.java
@@ -30,11 +30,13 @@ import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Model;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.repository.internal.MavenRepositorySystemSession;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
+import org.eclipse.aether.repository.LocalRepository;
 import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
 
 /**
  * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
@@ -92,8 +94,9 @@ public class DeployFileMojoTest
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-        MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
-        repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+        DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
+        repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
+                .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
         
         String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
@@ -193,8 +196,9 @@ public class DeployFileMojoTest
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-        MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
-        repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+        DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
+        repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
+                .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
 
         String classifier = ( String ) getVariableValueFromObject( mojo, "classifier" );
@@ -241,8 +245,9 @@ public class DeployFileMojoTest
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
         when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-        MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
-        repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( LOCAL_REPO ) );
+        DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
+        repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
+                .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
         when( buildingRequest.getRepositorySession() ).thenReturn( repositorySession );
 
         String groupId = (String) getVariableValueFromObject( mojo, "groupId" );
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
index 6131f79..0b6a0a9 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployFileMojoUnitTest.java
@@ -22,6 +22,7 @@ package org.apache.maven.plugins.deploy;
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+import org.apache.maven.api.plugin.MojoException;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Parent;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -78,7 +79,7 @@ public class DeployFileMojoUnitTest
             this.model = model;
         }
 
-        protected Model readModel(File pomFile) throws MojoExecutionException {
+        protected Model readModel(File pomFile) throws MojoException {
             return model;
         }
     }
@@ -91,7 +92,7 @@ public class DeployFileMojoUnitTest
 
         try {
             mojo.initProperties();
-        } catch (MojoExecutionException expected) {
+        } catch (MojoException expected) {
             assertTrue( true ); // missing artifactId and packaging
         }
 
@@ -105,7 +106,7 @@ public class DeployFileMojoUnitTest
 
         try {
             mojo.initProperties();
-        } catch (MojoExecutionException expected) {
+        } catch (MojoException expected) {
             assertTrue( true ); // missing packaging
         }
 
@@ -120,7 +121,7 @@ public class DeployFileMojoUnitTest
 
         try {
             mojo.initProperties();
-        } catch (MojoExecutionException expected) {
+        } catch (MojoException expected) {
             assertTrue( true ); // missing version and packaging
         }
 
diff --git a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
index 0d9e45b..c747633 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
@@ -19,29 +19,23 @@ package org.apache.maven.plugins.deploy;
  * under the License.
  */
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
 import java.io.File;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
 
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.api.RemoteRepository;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.MojoException;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.apache.maven.plugins.deploy.stubs.ArtifactDeployerStub;
 import org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub;
 import org.apache.maven.plugins.deploy.stubs.DeployArtifactStub;
+import org.apache.maven.plugins.deploy.stubs.ProjectDeployerStub;
+import org.apache.maven.plugins.deploy.stubs.ProjectStub;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
-import org.apache.maven.shared.transfer.project.deploy.ProjectDeployerRequest;
 import org.codehaus.plexus.util.FileUtils;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.internal.impl.SimpleLocalRepositoryManagerFactory;
@@ -51,6 +45,10 @@ import org.mockito.InjectMocks;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
 /**
  * @author <a href="mailto:aramirez@apache.org">Allan Ramirez</a>
  */
@@ -67,10 +65,8 @@ public class DeployMojoTest
     
     DeployArtifactStub artifact;
     
-    MavenProjectStub project = new MavenProjectStub();
-
     @Mock
-    private MavenSession session;
+    private Session session;
     
     @InjectMocks
     private DeployMojo mojo;
@@ -133,7 +129,6 @@ public class DeployMojoTest
         assertNotNull( mojo );
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
-        when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
         DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
         repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
                 .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
@@ -305,7 +300,6 @@ public class DeployMojoTest
         assertNotNull( mojo );
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
-        when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
         DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
         repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
                 .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
@@ -376,8 +370,7 @@ public class DeployMojoTest
         MockitoAnnotations.initMocks( this );
 
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
-        when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
-        
+
         setVariableValueToObject( mojo, "session", session );
         
         assertNotNull( mojo );
@@ -398,7 +391,7 @@ public class DeployMojoTest
 
             fail( "Did not throw mojo execution exception" );
         }
-        catch( MojoExecutionException e )
+        catch( MojoException e )
         {
             //expected
         }
@@ -418,7 +411,6 @@ public class DeployMojoTest
         assertNotNull( mojo );
         
         ProjectBuildingRequest buildingRequest = mock ( ProjectBuildingRequest.class );
-        when( session.getProjectBuildingRequest() ).thenReturn( buildingRequest );
         DefaultRepositorySystemSession repositorySession = MavenRepositorySystemUtils.newSession();
         repositorySession.setLocalRepositoryManager(  new SimpleLocalRepositoryManagerFactory()
                 .newInstance( repositorySession, new LocalRepository( LOCAL_REPO ) ) );
@@ -515,9 +507,9 @@ public class DeployMojoTest
         
         assertNotNull( mojo );
         
-        ArtifactDeployerStub deployer = new ArtifactDeployerStub();
+        ProjectDeployerStub deployer = new ProjectDeployerStub();
         
-        setVariableValueToObject( mojo, "deployer", deployer );
+        setVariableValueToObject( mojo, "projectDeployer", deployer );
         
         File file = new File( getBasedir(),
                               "target/test-classes/unit/basic-deploy-scp/target/" +
@@ -563,19 +555,14 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
         ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
-
-        ProjectDeployerRequest pdr =
-            new ProjectDeployerRequest()
-                .setProject( project )
-                .setAltDeploymentRepository( "altDeploymentRepository::default::http://localhost" );
+        mojo.altDeploymentRepository = "altDeploymentRepository::default::http://localhost";
 
         assertEquals( repository,
-                mojo.getDeploymentRepository( pdr ) );
+                mojo.getDeploymentRepository( true ) );
 
     }
 
@@ -584,22 +571,18 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
         ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
+        mojo.altDeploymentRepository = "altDeploymentRepository::legacy::http://localhost";
 
-        ProjectDeployerRequest pdr =
-            new ProjectDeployerRequest()
-                .setProject( project )
-                .setAltDeploymentRepository( "altDeploymentRepository::legacy::http://localhost" );
         try
         {
-            mojo.getDeploymentRepository( pdr );
+            mojo.getDeploymentRepository( true );
             fail( "Should throw: Invalid legacy syntax and layout for repository." );
         }
-        catch( MojoFailureException e )
+        catch( MojoException e )
         {
             assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
             assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::http://localhost\" instead, and only default layout is supported.");
@@ -611,22 +594,18 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
         ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
+        mojo.altDeploymentRepository = "altDeploymentRepository::hey::wow::foo::http://localhost";
 
-        ProjectDeployerRequest pdr =
-                new ProjectDeployerRequest()
-                        .setProject( project )
-                        .setAltDeploymentRepository( "altDeploymentRepository::hey::wow::foo::http://localhost" );
         try
         {
-            mojo.getDeploymentRepository( pdr );
+            mojo.getDeploymentRepository( true );
             fail( "Should throw: Invalid legacy syntax and layout for repository." );
         }
-        catch( MojoFailureException e )
+        catch( MojoException e )
         {
             assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
             assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::wow::foo::http://localhost\" instead, and only default layout is supported.");
@@ -638,41 +617,32 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "scm:svn:http://localhost"
         ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
-
-        ProjectDeployerRequest pdr =
-                new ProjectDeployerRequest()
-                        .setProject( project )
-                        .setAltDeploymentRepository( "altDeploymentRepository::default::scm:svn:http://localhost" );
+        mojo.altDeploymentRepository = "altDeploymentRepository::default::scm:svn:http://localhost";
 
         assertEquals( repository,
-                mojo.getDeploymentRepository( pdr ) );
+                mojo.getDeploymentRepository( true ) );
     }
     public void testLegacyScmSvnAltDeploymentRepository()
             throws Exception
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altDeploymentRepository", "http://localhost"
         ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
+        mojo.altDeploymentRepository = "altDeploymentRepository::legacy::scm:svn:http://localhost";
 
-        ProjectDeployerRequest pdr =
-                new ProjectDeployerRequest()
-                        .setProject( project )
-                        .setAltDeploymentRepository( "altDeploymentRepository::legacy::scm:svn:http://localhost" );
         try
         {
-            mojo.getDeploymentRepository( pdr );
+            mojo.getDeploymentRepository( true );
             fail( "Should throw: Invalid legacy syntax and layout for repository." );
         }
-        catch( MojoFailureException e )
+        catch( MojoException e )
         {
             assertEquals( e.getMessage(), "Invalid legacy syntax and layout for repository.");
             assertEquals( e.getLongMessage(), "Invalid legacy syntax and layout for alternative repository. Use \"altDeploymentRepository::scm:svn:http://localhost\" instead, and only default layout is supported.");
@@ -684,18 +654,14 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altSnapshotDeploymentRepository", "http://localhost"
                                                        ) ).thenReturn( repository );
 
-        project.setVersion( "1.0-SNAPSHOT" );
+        mojo.altDeploymentRepository = "altSnapshotDeploymentRepository::http://localhost";
 
-        ProjectDeployerRequest pdr =
-                        new ProjectDeployerRequest()
-                            .setProject( project )
-                            .setAltDeploymentRepository( "altSnapshotDeploymentRepository::http://localhost" );
         assertEquals( repository,
-                      mojo.getDeploymentRepository( pdr ));
+                      mojo.getDeploymentRepository( true ));
     }
 
     public void testAltReleaseDeploymentRepository()
@@ -703,18 +669,13 @@ public class DeployMojoTest
     {
         DeployMojo mojo = spy( new DeployMojo() );
 
-        ArtifactRepository repository = mock( ArtifactRepository.class );
+        RemoteRepository repository = mock( RemoteRepository.class );
         when( mojo.createDeploymentArtifactRepository( "altReleaseDeploymentRepository", "http://localhost" ) ).thenReturn( repository );
 
-        project.setVersion( "1.0" );
-
-        ProjectDeployerRequest pdr =
-                        new ProjectDeployerRequest()
-                            .setProject( project )
-                            .setAltReleaseDeploymentRepository( "altReleaseDeploymentRepository::http://localhost" );
+        mojo.altDeploymentRepository = "altReleaseDeploymentRepository::http://localhost";
 
         assertEquals( repository,
-                      mojo.getDeploymentRepository( pdr ));
+                      mojo.getDeploymentRepository( false ));
     }
     
     private void addFileToList( File file, List<String> fileList )
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectDeployerStub.java
similarity index 53%
rename from src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
rename to src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectDeployerStub.java
index d0b47d4..f7be122 100644
--- a/src/test/java/org/apache/maven/plugins/deploy/stubs/ArtifactDeployerStub.java
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectDeployerStub.java
@@ -19,29 +19,16 @@ package org.apache.maven.plugins.deploy.stubs;
  * under the License.
  */
 
-import java.util.Collection;
+import org.apache.maven.api.services.ProjectDeployer;
+import org.apache.maven.api.services.ProjectDeployerException;
+import org.apache.maven.api.services.ProjectDeployerRequest;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
-import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
-
-public class ArtifactDeployerStub
-    implements ArtifactDeployer
+public class ProjectDeployerStub
+        implements ProjectDeployer
 {
-
     @Override
-    public void deploy( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts )
-        throws ArtifactDeployerException
+    public void deploy( ProjectDeployerRequest request ) throws ProjectDeployerException, IllegalArgumentException
     {
-        // does nothing
-    }
 
-    @Override
-    public void deploy( ProjectBuildingRequest arg0, ArtifactRepository arg1, Collection<Artifact> arg2)
-        throws ArtifactDeployerException
-    {
-        // does nothing
     }
 }
diff --git a/src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectStub.java b/src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectStub.java
new file mode 100644
index 0000000..12df4a8
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/deploy/stubs/ProjectStub.java
@@ -0,0 +1,115 @@
+package org.apache.maven.plugins.deploy.stubs;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.annotation.Nonnull;
+
+import java.nio.file.Path;
+import java.util.List;
+
+import org.apache.maven.api.Artifact;
+import org.apache.maven.api.Dependency;
+import org.apache.maven.api.Project;
+import org.apache.maven.model.Model;
+
+public class ProjectStub implements Project
+{
+    private String groupId;
+    private String artifactId;
+    private String version;
+
+    @Nonnull
+    @Override
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    @Nonnull
+    @Override
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+
+    @Nonnull
+    @Override
+    public String getVersion()
+    {
+        return version;
+    }
+
+    @Nonnull
+    @Override
+    public String getPackaging()
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public Artifact getArtifact()
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public Model getModel()
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public Path getPomPath()
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public List<Dependency> getDependencies()
+    {
+        return null;
+    }
+
+    @Nonnull
+    @Override
+    public List<Dependency> getManagedDependencies()
+    {
+        return null;
+    }
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public void setArtifactId( String artifactId )
+    {
+        this.artifactId = artifactId;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+}