Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mvn dependency:go-offline - how do you set params on the command line or at all

I want to download everything except my own dependencies, which I haven't compiled yet. I think what I need is excludeGroupIds, but how to I set it, or anything else in https://maven.apache.org/plugins/maven-dependency-plugin/go-offline-mojo.html on the command line?

I have tried this

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

I have also tried to set them in pom.xml and settings.xml, and not been able to make them have any effect.

like image 274
Alex028502 Avatar asked Jun 30 '18 09:06

Alex028502


People also ask

What does mvn dependency go-offline do?

The go-offline goal of the Maven Dependency plugin downloads all the required dependencies and plugins for the project, based on the pom file. The –o option tells Maven to work offline and not check the Internet for anything. However, it is not without its issues.

What does mvn dependency resolve do?

Description: Goal that resolves the project dependencies from the repository.

What is the Maven command to download dependencies?

You can use the Maven Dependency Plugin to download dependencies. Run mvn dependency:copy-dependencies , to download all your dependencies and save them in the target/dependency folder.


1 Answers

From checking the code of the maven-dependency-plugin, I'm pretty sure this is a bug, in the sense that the filters are not applied for go-offline. Here's the code that resolves dependencies in the go-offline mojo implementation (version 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" );
}

In contract, here is the code that resolves dependencies for the 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 ) ) );

    ...

It's pretty clear that the code of go-offline is not applying those filters when resolving dependencies. So I've inserted a ticket for the project to confirm: https://issues.apache.org/jira/browse/MDEP-725

like image 178
M A Avatar answered Oct 27 '22 03:10

M A