code: public List<Model> getModelsRecursively ( String groupId, String artifactId, String version, File pom )
          throws ArtifactResolutionException, ArtifactNotFoundException, IOException, XmlPullParserException
      {
          List<Model> models = null;
          Model model = getPomModel( groupId, artifactId, version, pom );
  
          Parent parent = model.getParent();
  
          // recurse into the parent
          if ( parent != null )
          {
              // get the relative path
              String relativePath = parent.getRelativePath();
              if ( StringUtils.isEmpty( relativePath ) )
              {
                  relativePath = "../pom.xml";
              }
              // calculate the recursive path
              File parentPom = new File( pom.getParent(), relativePath );
  
              // if relative path is a directory, append pom.xml
              if ( parentPom.isDirectory() )
              {
                  parentPom = new File( parentPom, "pom.xml" );
              }
  
              models = getModelsRecursively( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), parentPom );
          }
          else
          {
              // only create it here since I'm not at the top
              models = new ArrayList<Model>();
          }
          models.add( model );
  
          return models;
      }
docs: This method loops through all the parents, getting
  each pom model and then its parent.
  
  @param groupId the group id
  @param artifactId the artifact id
  @param version the version
  @param pom the pom
  
  @return the models recursively
  
  @throws ArtifactResolutionException the artifact resolution exception
  @throws ArtifactNotFoundException the artifact not found exception
  @throws IOException Signals that an I/O exception has occurred.
  @throws XmlPullParserException the xml pull parser exception