Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aether-users] Collecting list of transitive dependencies *and* necessary parent POMs

Hi Igor,

> We have code that creates dependency tree with parent nodes we can
> probably open source. 

that would be great.

> In the mean time, here is the basic idea
> 
> * Maven 3.2.4+ has new ArtifactDescriptorReaderDelegate, which I
> extended to create Aether parent project dependencies artifacts. These
> artifacts have marker property to distinguish them from other artifacts.
> 
> * The custom ArtifactDescriptorReaderDelegate implementation is enabled
> using DefaultRepositorySystemSession#setConfigProperty (see how this is
> used in DefaultArtifactDescriptorReader around line 222)
> 
> * DependencyGraphTransformer is used to rearrange project/parent nodes
> in the resolved graph. You probably don't need this If you just need
> flat list of artifacts to download.

I think my idea is fairly similar, although yours is probably more
general than my implementation. Instead of wrapping the
DefaultArtifactDescriptorReader, I wrap the DefaultModelBuilder:

> public class ParentPomsAsDependencyModelBuilder implements ModelBuilder {
> 
>     private final DefaultModelBuilder delegate;
> 
>     public ParentPomsAsDependencyModelBuilder() {
>         delegate = new DefaultModelBuilderFactory().newInstance();
>     }
> 
>     @Override
>     public ModelBuildingResult build(ModelBuildingRequest request) throws ModelBuildingException {
>         return new ParentPomsAsDependencyModelBuildingResult(delegate.build(request));
>     }
> 
>     private static class ParentPomsAsDependencyModelBuildingResult implements ModelBuildingResult {
> 
>         private final ModelBuildingResult wrapped;
> 
>         public ParentPomsAsDependencyModelBuildingResult(ModelBuildingResult wrapped) {
>             this.wrapped = wrapped;
>         }
> 
>         @Override
>         public Model getEffectiveModel() {
>             Model original = wrapped.getEffectiveModel();
>             Parent parent = original.getParent();
>             if (parent != null) {
>                 Model clone = original.clone();
>                 Dependency parentDependency = new Dependency();
>                 parentDependency.setGroupId(parent.getGroupId());
>                 parentDependency.setArtifactId(parent.getArtifactId());
>                 parentDependency.setVersion(parent.getVersion());
>                 parentDependency.setScope("compile");
>                 parentDependency.setType("pom");
>                 clone.addDependency(parentDependency);
>                 return clone;
>             } else {
>                 return original;
>             }
>         }

As far as I can see, this has the desired effect, even if it is not
particularly elegant.

Best wishes,

Andreas

-- 
Codetrails GmbH
The knowledge transfer company

Robert-Bosch-Str. 7, 64293 Darmstadt
Phone: +49-6151-276-7092
Mobile: +49-170-811-3791
http://www.codetrails.com/

Managing Director: Dr. Marcel Bruch
Handelsregister: Darmstadt HRB 91940


Back to the top