diff --git a/src/it/mrm/repository/ResourceArtifact-1.0.pom b/src/it/mrm/repository/ResourceArtifact-1.0.pom index 322146d20..e44e1cd00 100644 --- a/src/it/mrm/repository/ResourceArtifact-1.0.pom +++ b/src/it/mrm/repository/ResourceArtifact-1.0.pom @@ -27,4 +27,4 @@ 1.0 jar - \ No newline at end of file + diff --git a/src/it/mrm/repository/ResourceArtifact-relocation-1.0.pom b/src/it/mrm/repository/ResourceArtifact-relocation-1.0.pom new file mode 100644 index 000000000..d992d4070 --- /dev/null +++ b/src/it/mrm/repository/ResourceArtifact-relocation-1.0.pom @@ -0,0 +1,36 @@ + + + + + 4.0.0 + org.apache.maven.its.dependency + ResourceArtifact-relocation + 1.0 + pom + + + + ResourceArtifact + + + + diff --git a/src/it/mrm/repository/get-artifact-1.0.jar b/src/it/mrm/repository/get-artifact-1.0.jar deleted file mode 100644 index 226277c38..000000000 Binary files a/src/it/mrm/repository/get-artifact-1.0.jar and /dev/null differ diff --git a/src/it/mrm/repository/get-artifact-maven-plugin-1.0.jar b/src/it/mrm/repository/get-artifact-maven-plugin-1.0.jar deleted file mode 100644 index 226277c38..000000000 Binary files a/src/it/mrm/repository/get-artifact-maven-plugin-1.0.jar and /dev/null differ diff --git a/src/it/mrm/repository/get-artifact-transitive-1.0.jar b/src/it/mrm/repository/get-artifact-transitive-1.0.jar deleted file mode 100644 index 226277c38..000000000 Binary files a/src/it/mrm/repository/get-artifact-transitive-1.0.jar and /dev/null differ diff --git a/src/it/projects/copy-cli/test.properties b/src/it/projects/copy-cli/test.properties index 356610c4b..8af858c29 100644 --- a/src/it/projects/copy-cli/test.properties +++ b/src/it/projects/copy-cli/test.properties @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -artifact=org.apache.maven:maven-model:2.0.6 +artifact=org.apache.maven.its.dependency:a1:1.0.0 diff --git a/src/it/projects/copy-cli/verify.bsh b/src/it/projects/copy-cli/verify.groovy similarity index 70% rename from src/it/projects/copy-cli/verify.bsh rename to src/it/projects/copy-cli/verify.groovy index da93772de..37dc01924 100644 --- a/src/it/projects/copy-cli/verify.bsh +++ b/src/it/projects/copy-cli/verify.groovy @@ -17,21 +17,4 @@ * under the License. */ -import java.io.*; - -File libDir = new File( basedir, "target/dependency" ); - -String[] expectedFiles = { - "maven-model-2.0.6.jar", -}; - -for ( String expectedFile : expectedFiles ) -{ - File file = new File( libDir, expectedFile ); - if ( !file.isFile() ) - { - throw new Exception( "Missing file " + file ); - } -} - -return true; +assert new File( basedir, 'target/dependency/a1-1.0.0.jar' ).isFile(); diff --git a/src/it/projects/copy-relocation/invoker.properties b/src/it/projects/copy-relocation/invoker.properties new file mode 100644 index 000000000..f50e476fd --- /dev/null +++ b/src/it/projects/copy-relocation/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = clean process-sources diff --git a/src/it/projects/copy-relocation/pom.xml b/src/it/projects/copy-relocation/pom.xml new file mode 100644 index 000000000..197d49f27 --- /dev/null +++ b/src/it/projects/copy-relocation/pom.xml @@ -0,0 +1,64 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test + + Test dependency:copy with relocation + + + + UTF-8 + + + + + + maven-dependency-plugin + @project.version@ + + + test + + copy + + + + + org.apache.maven.its.dependency + ResourceArtifact-relocation + 1.0 + + + + + + + + + diff --git a/src/it/projects/copy-relocation/verify.groovy b/src/it/projects/copy-relocation/verify.groovy new file mode 100644 index 000000000..672e5f1ec --- /dev/null +++ b/src/it/projects/copy-relocation/verify.groovy @@ -0,0 +1,20 @@ +/* + * 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. + */ + +assert new File( basedir, 'target/dependency/ResourceArtifact-1.0.jar' ).isFile(); diff --git a/src/it/projects/copy/pom.xml b/src/it/projects/copy/pom.xml index 5e2a00c16..a2a5d6950 100644 --- a/src/it/projects/copy/pom.xml +++ b/src/it/projects/copy/pom.xml @@ -50,9 +50,9 @@ - org.apache.maven - maven-model - 2.0.6 + org.apache.maven.its.dependency + a1 + 1.0.0 diff --git a/src/it/projects/copy/verify.groovy b/src/it/projects/copy/verify.groovy new file mode 100644 index 000000000..37dc01924 --- /dev/null +++ b/src/it/projects/copy/verify.groovy @@ -0,0 +1,20 @@ +/* + * 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. + */ + +assert new File( basedir, 'target/dependency/a1-1.0.0.jar' ).isFile(); diff --git a/src/it/projects/unpack-relocation/invoker.properties b/src/it/projects/unpack-relocation/invoker.properties new file mode 100644 index 000000000..f50e476fd --- /dev/null +++ b/src/it/projects/unpack-relocation/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = clean process-sources diff --git a/src/it/projects/unpack-relocation/pom.xml b/src/it/projects/unpack-relocation/pom.xml new file mode 100644 index 000000000..9436753bf --- /dev/null +++ b/src/it/projects/unpack-relocation/pom.xml @@ -0,0 +1,68 @@ + + + + + + + 4.0.0 + + org.apache.maven.its.dependency + test + 1.0-SNAPSHOT + + Test + + Test dependency:unpack with relocation + + + + UTF-8 + + + + + + + maven-dependency-plugin + @project.version@ + + + unpack + + unpack + + + ${project.build.directory}/ResourceArtifact + + + org.apache.maven.its.dependency + ResourceArtifact-relocation + 1.0 + + + + + + + + + diff --git a/src/it/projects/copy/verify.bsh b/src/it/projects/unpack-relocation/verify.groovy similarity index 70% rename from src/it/projects/copy/verify.bsh rename to src/it/projects/unpack-relocation/verify.groovy index da93772de..7c14f5f6e 100644 --- a/src/it/projects/copy/verify.bsh +++ b/src/it/projects/unpack-relocation/verify.groovy @@ -17,21 +17,8 @@ * under the License. */ -import java.io.*; -File libDir = new File( basedir, "target/dependency" ); +assert new File(basedir, 'target/ResourceArtifact/META-INF/MANIFEST.MF').isFile() +assert new File(basedir, 'target/ResourceArtifact/resource1.txt').isFile() +assert new File(basedir, 'target/ResourceArtifact/resource2.txt').isFile() -String[] expectedFiles = { - "maven-model-2.0.6.jar", -}; - -for ( String expectedFile : expectedFiles ) -{ - File file = new File( libDir, expectedFile ); - if ( !file.isFile() ) - { - throw new Exception( "Missing file " + file ); - } -} - -return true; diff --git a/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java index 15866fd8e..592505993 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/ListClassesMojo.java @@ -35,6 +35,7 @@ import org.apache.maven.plugins.dependency.utils.ParamArtifact; import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.DependencyResolutionException; @@ -170,7 +171,10 @@ public void execute() throws MojoExecutionException, MojoFailureException { resolverUtil.resolveArtifact(artifact, resolverUtil.remoteRepositories(remoteRepositories)); printClassesFromArtifactResult(a.getFile()); } - } catch (IOException | ArtifactResolutionException | DependencyResolutionException e) { + } catch (IOException + | ArtifactResolutionException + | DependencyResolutionException + | ArtifactDescriptorException e) { throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e); } } diff --git a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java index 0d488055b..363446d51 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/PropertiesMojo.java @@ -33,6 +33,7 @@ import org.apache.maven.plugins.dependency.utils.ParamArtifact; import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.project.MavenProject; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; /** @@ -134,7 +135,7 @@ public void execute() throws MojoExecutionException { .setProperty( toConflictId(artifact), artifact.getFile().getAbsolutePath()); } - } catch (ArtifactResolutionException e) { + } catch (ArtifactResolutionException | ArtifactDescriptorException e) { throw new MojoExecutionException("Couldn't download artifact: " + e.getMessage(), e); } } diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java index 88914298e..1c5a55132 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/AbstractFromConfigurationMojo.java @@ -35,6 +35,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.dependency.AbstractDependencyMojo; import org.apache.maven.plugins.dependency.utils.DependencyUtil; +import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; @@ -45,9 +46,8 @@ import org.eclipse.aether.artifact.DefaultArtifact; import org.eclipse.aether.repository.LocalRepository; import org.eclipse.aether.repository.LocalRepositoryManager; -import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; -import org.eclipse.aether.resolution.ArtifactResult; import org.sonatype.plexus.build.incremental.BuildContext; /** @@ -122,15 +122,19 @@ public abstract class AbstractFromConfigurationMojo extends AbstractDependencyMo private final RepositorySystem repositorySystem; + private final ResolverUtil resolverUtil; + protected AbstractFromConfigurationMojo( MavenSession session, BuildContext buildContext, MavenProject project, ArtifactHandlerManager artifactHandlerManager, - RepositorySystem repositorySystem) { + RepositorySystem repositorySystem, + ResolverUtil resolverUtil) { super(session, buildContext, project); this.artifactHandlerManager = artifactHandlerManager; this.repositorySystem = repositorySystem; + this.resolverUtil = resolverUtil; } abstract ArtifactItemFilter getMarkedArtifactFilter(ArtifactItem item); @@ -252,11 +256,11 @@ protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionEx RepositorySystemSession repositorySession = createSystemSessionForLocalRepo(); - ArtifactRequest request = new ArtifactRequest(artifact, getProject().getRemoteProjectRepositories(), null); - ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySession, request); - return RepositoryUtils.toArtifact(artifactResult.getArtifact()); + org.eclipse.aether.artifact.Artifact resolvedArtifact = resolverUtil.resolveArtifact( + artifact, getProject().getRemoteProjectRepositories(), repositorySession); + return RepositoryUtils.toArtifact(resolvedArtifact); - } catch (ArtifactResolutionException e) { + } catch (ArtifactResolutionException | ArtifactDescriptorException e) { throw new MojoExecutionException("Unable to find/resolve artifact.", e); } } diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java index dab686a50..644c6121e 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java @@ -33,6 +33,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.dependency.utils.CopyUtil; +import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter; import org.apache.maven.plugins.dependency.utils.filters.DestFileFilter; import org.apache.maven.project.MavenProject; @@ -93,8 +94,9 @@ public CopyMojo( MavenProject project, ArtifactHandlerManager artifactHandlerManager, CopyUtil copyUtil, - RepositorySystem repositorySystem) { - super(session, buildContext, project, artifactHandlerManager, repositorySystem); + RepositorySystem repositorySystem, + ResolverUtil resolverUtil) { + super(session, buildContext, project, artifactHandlerManager, repositorySystem, resolverUtil); this.copyUtil = copyUtil; } diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java index e4854371c..005299cdc 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/UnpackMojo.java @@ -30,6 +30,7 @@ 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.plugins.dependency.utils.ResolverUtil; import org.apache.maven.plugins.dependency.utils.UnpackUtil; import org.apache.maven.plugins.dependency.utils.filters.ArtifactItemFilter; import org.apache.maven.plugins.dependency.utils.filters.MarkerFileFilter; @@ -111,8 +112,9 @@ public UnpackMojo( MavenProject project, ArtifactHandlerManager artifactHandlerManager, UnpackUtil unpackUtil, - RepositorySystem repositorySystem) { - super(session, buildContext, project, artifactHandlerManager, repositorySystem); + RepositorySystem repositorySystem, + ResolverUtil resolverUtil) { + super(session, buildContext, project, artifactHandlerManager, repositorySystem, resolverUtil); this.unpackUtil = unpackUtil; } diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java index de605f1aa..a0a23ca4e 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/AbstractDependencyFilterMojo.java @@ -57,6 +57,7 @@ import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; import org.apache.maven.shared.artifact.filter.collection.TypeFilter; import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.DependencyResolutionException; import org.sonatype.plexus.build.incremental.BuildContext; @@ -401,7 +402,7 @@ private void addParentArtifacts(MavenProject project, Set artifacts) t RepositoryUtils.toArtifact(project.getArtifact()), project.getRemoteProjectRepositories()); artifacts.add(RepositoryUtils.toArtifact(resolvedArtifact)); - } catch (ArtifactResolutionException e) { + } catch (ArtifactResolutionException | ArtifactDescriptorException e) { throw new MojoExecutionException(e.getMessage(), e); } } @@ -492,7 +493,7 @@ private Set resolve(Set artifact org.eclipse.aether.artifact.Artifact resolveArtifact = resolverUtil.resolveArtifact(artifact, getProject().getRemoteProjectRepositories()); resolvedArtifacts.add(RepositoryUtils.toArtifact(resolveArtifact)); - } catch (ArtifactResolutionException ex) { + } catch (ArtifactResolutionException | ArtifactDescriptorException ex) { // an error occurred during resolution, log it and continue getLog().debug("error resolving: " + artifact, ex); if (stopOnFailure) { diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java index 9378fd524..43a385035 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java @@ -48,6 +48,7 @@ import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller; import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException; import org.apache.maven.shared.transfer.repository.RepositoryManager; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.util.artifact.SubArtifact; import org.sonatype.plexus.build.incremental.BuildContext; @@ -299,7 +300,7 @@ private void copySignatureFile(Artifact artifact, File destDir, String destFileN org.eclipse.aether.artifact.Artifact resolvedSignature = getResolverUtil() .resolveArtifact(aSignatureArtifact, getProject().getRemoteProjectRepositories()); signatureFile = resolvedSignature.getFile(); - } catch (ArtifactResolutionException e) { + } catch (ArtifactResolutionException | ArtifactDescriptorException e) { getLog().warn("Failed to resolve signature file for artifact: " + artifact, e); } } @@ -380,7 +381,7 @@ protected Artifact getResolvedPomArtifact(Artifact artifact) { org.eclipse.aether.artifact.Artifact resolvedPom = getResolverUtil().resolveArtifact(aPomArtifact, getProject().getRemoteProjectRepositories()); pomArtifact = RepositoryUtils.toArtifact(resolvedPom); - } catch (ArtifactResolutionException e) { + } catch (ArtifactResolutionException | ArtifactDescriptorException e) { getLog().info(e.getMessage()); } return pomArtifact; diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java index 110b294ae..da0726d3d 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/GoOfflineMojo.java @@ -55,6 +55,7 @@ import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; import org.apache.maven.shared.artifact.filter.collection.TypeFilter; import org.eclipse.aether.artifact.ArtifactTypeRegistry; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.DependencyResolutionException; import org.sonatype.plexus.build.incremental.BuildContext; @@ -127,7 +128,10 @@ protected void doExecute() throws MojoExecutionException { + DependencyUtil.getFormattedFileName(RepositoryUtils.toArtifact(artifact), false)); } - } catch (ArtifactFilterException | ArtifactResolutionException | DependencyResolutionException e) { + } catch (ArtifactFilterException + | ArtifactResolutionException + | DependencyResolutionException + | ArtifactDescriptorException e) { throw new MojoExecutionException(e.getMessage(), e); } } diff --git a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java index b48998215..74ad8158e 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java +++ b/src/main/java/org/apache/maven/plugins/dependency/resolvers/ResolvePluginsMojo.java @@ -41,6 +41,7 @@ import org.apache.maven.plugins.dependency.utils.ResolverUtil; import org.apache.maven.project.MavenProject; import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.resolution.ArtifactDescriptorException; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.DependencyResolutionException; import org.sonatype.plexus.build.incremental.BuildContext; @@ -209,7 +210,10 @@ protected void doExecute() throws MojoExecutionException { DependencyUtil.write(output, outputFile, appendOutput, encoding); } } - } catch (IOException | ArtifactResolutionException | DependencyResolutionException e) { + } catch (IOException + | ArtifactResolutionException + | DependencyResolutionException + | ArtifactDescriptorException e) { throw new MojoExecutionException(e.getMessage(), e); } } diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java index 8ff22350f..60ca42c97 100644 --- a/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java +++ b/src/main/java/org/apache/maven/plugins/dependency/utils/ResolverUtil.java @@ -54,6 +54,9 @@ import org.eclipse.aether.graph.Dependency; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.aether.repository.RepositoryPolicy; +import org.eclipse.aether.resolution.ArtifactDescriptorException; +import org.eclipse.aether.resolution.ArtifactDescriptorRequest; +import org.eclipse.aether.resolution.ArtifactDescriptorResult; import org.eclipse.aether.resolution.ArtifactRequest; import org.eclipse.aether.resolution.ArtifactResolutionException; import org.eclipse.aether.resolution.ArtifactResult; @@ -101,7 +104,7 @@ public Collection collectDependencies(Dependency dependency) throws } /** - * Resolve given artifact. + * Resolve a given artifact. * * @param artifact an artifact to resolve * @param repositories remote repositories list @@ -109,10 +112,31 @@ public Collection collectDependencies(Dependency dependency) throws * @throws ArtifactResolutionException if the artifact could not be resolved */ public Artifact resolveArtifact(Artifact artifact, List repositories) - throws ArtifactResolutionException { + throws ArtifactResolutionException, ArtifactDescriptorException { MavenSession session = mavenSessionProvider.get(); - ArtifactRequest request = new ArtifactRequest(artifact, repositories, null); - ArtifactResult result = repositorySystem.resolveArtifact(session.getRepositorySession(), request); + return resolveArtifact(artifact, repositories, session.getRepositorySession()); + } + + /** + * Resolve a given artifact. + * + * @param artifact an artifact to resolve + * @param repositories remote repositories list + * @param session a repository system session + * @return resolved artifact + * @throws ArtifactResolutionException if the artifact could not be resolved + */ + public Artifact resolveArtifact( + Artifact artifact, List repositories, RepositorySystemSession session) + throws ArtifactResolutionException, ArtifactDescriptorException { + + ArtifactDescriptorResult artifactDescriptorResult = repositorySystem.readArtifactDescriptor( + session, new ArtifactDescriptorRequest(artifact, repositories, null)); + + Artifact artifactToResolve = artifactDescriptorResult.getArtifact(); + + ArtifactRequest request = new ArtifactRequest(artifactToResolve, repositories, null); + ArtifactResult result = repositorySystem.resolveArtifact(session, request); return result.getArtifact(); } @@ -123,7 +147,7 @@ public Artifact resolveArtifact(Artifact artifact, List reposi * @return resolved artifact * @throws ArtifactResolutionException if the artifact could not be resolved */ - public Artifact resolvePlugin(Plugin plugin) throws ArtifactResolutionException { + public Artifact resolvePlugin(Plugin plugin) throws ArtifactResolutionException, ArtifactDescriptorException { MavenSession session = mavenSessionProvider.get(); Artifact artifact = toArtifact(plugin); return resolveArtifact(artifact, session.getCurrentProject().getRemotePluginRepositories());