mvndependency:go-offline-如何在命令行或完全设置参数

时间:2018-06-30 09:57:12

标签: maven maven-dependency-plugin

除了我自己的依赖项(我尚未编译)之外,我想下载所有内容。我认为我需要的是excludeGroupIds,但是如何设置它,或者在命令行中的https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html中呢?

我已经尝试过了

mvn dependency:go-offline -DexcludeGroupIds=com.example

我还尝试将它们设置为pom.xmlsettings.xml,但无法使它们生效。

1 个答案:

答案 0 :(得分:4)

通过检查maven-dependency-plugin的代码,我可以肯定这是一个错误,就意味着过滤器不适用于go-offline。以下是解析go-offline mojo implementation(版本3.1.3-SNAPSHOT)中的依赖关系的代码:

protected Set<Artifact> resolveDependencyArtifacts()
        throws DependencyResolverException
{
    final Collection<Dependency> dependencies = getProject().getDependencies();
    final Set<DependableCoordinate> dependableCoordinates = new HashSet<>();

    final ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();

    for ( Dependency dependency : dependencies )
    {
        dependableCoordinates.add( createDependendableCoordinateFromDependency( dependency ) );
    }

    return resolveDependableCoordinate( buildingRequest, dependableCoordinates, "dependencies" );
}

契约中,这是解析resolve mojo的依赖关系的代码:

@Override
protected void doExecute()
    throws MojoExecutionException
{
    // get sets of dependencies
    results = this.getDependencySets( false, includeParents );

    ...
}

AbstractDependencyFilterMojo:

protected DependencyStatusSets getDependencySets( boolean stopOnFailure, boolean includeParents )
    throws MojoExecutionException
{
    // add filters in well known order, least specific to most specific
    FilterArtifacts filter = new FilterArtifacts();

    filter.addFilter( new ProjectTransitivityFilter( getProject().getDependencyArtifacts(),
                                                     this.excludeTransitive ) );

    filter.addFilter( new ScopeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeScope ),
                                       DependencyUtil.cleanToBeTokenizedString( this.excludeScope ) ) );

    filter.addFilter( new TypeFilter( DependencyUtil.cleanToBeTokenizedString( this.includeTypes ),
                                      DependencyUtil.cleanToBeTokenizedString( this.excludeTypes ) ) );

    filter.addFilter( new ClassifierFilter( DependencyUtil.cleanToBeTokenizedString( this.includeClassifiers ),
                                            DependencyUtil.cleanToBeTokenizedString( this.excludeClassifiers ) ) );

    filter.addFilter( new GroupIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeGroupIds ),
                                         DependencyUtil.cleanToBeTokenizedString( this.excludeGroupIds ) ) );

    filter.addFilter( new ArtifactIdFilter( DependencyUtil.cleanToBeTokenizedString( this.includeArtifactIds ),
                                            DependencyUtil.cleanToBeTokenizedString( this.excludeArtifactIds ) ) );

    ...

很明显,go-offline的代码在解决依赖项时未应用这些过滤器。因此,我为该项目插入了一张票证,以确认:https://issues.apache.org/jira/browse/MDEP-725