[ 
https://jira.codehaus.org/browse/MNG-5156?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Benjamin Bentmann closed MNG-5156.
----------------------------------

    Resolution: Not A Bug
      Assignee: Benjamin Bentmann

bq. I still think that it makes more sense for the 'test-framework' dependency 
to have a 'test' scope because the 'root' dependency enforces the 'test' scope 
explicitly
It's simply a matter of how one interprets a {{<dependency>}} declaration, 
usually they are meant to express requirements/needs. And if your own code 
itself requires foo only in runtime scope but a lib that you require for 
compilation requires foo in compile scope, it's safer to satisfy the stronger 
need and put foo into compile scope.

Whether the subtle differences between direct dependencies and transitive ones 
with regard to scope calculation make sense, is another question. In might have 
been more consistent to leave the concept of dependency enforcement to 
{{<dependencyManagement>}} but now it is like it is.

Back to your wrapping project: Keep in mind that transitive test and provided 
scope dependencies as well as optional dependencies are completely dropped from 
the graph, i.e. the act of wrapping a dependency heavily changes the resolved 
graph.

> org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator 
> doesn't take into account direct vs. transitive dependencies
> ------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: MNG-5156
>                 URL: https://jira.codehaus.org/browse/MNG-5156
>             Project: Maven 2 & 3
>          Issue Type: Bug
>          Components: Dependencies
>    Affects Versions: 3.0.2, 3.0.3
>         Environment: Irrelevant (I debugged the code and I provide an exact 
> location of the problem)
>            Reporter: Bisser
>            Assignee: Benjamin Bentmann
>            Priority: Minor
>         Attachments: pom.xml
>
>
> When calculating the scope of a dependency, Maven should assign to direct 
> dependencies higher priority than transitive dependencies.
> For example:
> com.acme:root:jar:1.0.0
> +- com.acme:test-framework:jar:1.0.0:test                 <<<<<<<<<<<<< 
> direct dependency
> \- com.acme:another-module:jar:1.0.0:compile
>    \- com.acme:test-framework:jar:1.0.0:compile           <<<<<<<<<<<<< 
> transitive dependency
> We can see that the 'root' project references test-framework directly with 
> scope 'test'. However, the same test-framework also has a 'compile' scope, 
> but via a transitive dependency. I believe that the final scope should be 
> 'test' -- that's the explicit desire of the author of project 'root'.
> However, when I do roughly the following:
>    ProjectBuilder projectBuilder = 
> plexusContainer.lookup(ProjectBuilder.class);
>    ProjectBuildingRequest projectBuildingRequest = ....;
>    projectBuildingRequest.setResolveDependencies(true);
>    ...
>    ProjectBuildingResult result = projectBuilder.build(pom, 
> projectBuildingRequest);
>    MavenProject proj = result.getProject();
>    ...
>    Set<Artifact> artifacts = proj.getArtifacts();
> The 'test-framework' Artifact has a scope of 'compile'!!! (I will provide 
> more code, if you'd like.)
> After some debugging to find out the reason for this, I reached class 
> org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator. 
> There, in method chooseEffectiveScope, there's the following code:
>         else if ( scopes.contains( JavaScopes.COMPILE ) )
>         {
>             effectiveScope = JavaScopes.COMPILE;
>         }
> So, no attention is paid whether the dependency is direct or transitive. If 
> there's *any* dependency with scope 'compile', then the conflict is resolved 
> by setting the final scope to 'compile'. But, as I said above, I believe the 
> final scope should be 'test'.
> Here's a relevant stack trace:
> JavaEffectiveScopeCalculator.chooseEffectiveScope(Set<String>) line: 220      
> JavaEffectiveScopeCalculator.resolve(ConflictGroup, Map<?,?>, Set<?>) line: 
> 139       
> JavaEffectiveScopeCalculator.transformGraph(DependencyNode, 
> DependencyGraphTransformationContext) line: 92    
> ChainedDependencyGraphTransformer.transformGraph(DependencyNode, 
> DependencyGraphTransformationContext) line: 75       
> DefaultDependencyCollector.collectDependencies(RepositorySystemSession, 
> CollectRequest) line: 253     
> DefaultRepositorySystem.collectDependencies(RepositorySystemSession, 
> CollectRequest) line: 345        
> DefaultProjectDependenciesResolver.resolve(DependencyResolutionRequest) line: 
> 131     
> DefaultProjectBuilder.build(File, ModelSource, 
> DefaultProjectBuilder$InternalConfig) line: 166        
> DefaultProjectBuilder.build(ModelSource, ProjectBuildingRequest) line: 108    
> .
> .
> .
> By the way, the Dependency Plugin reports this:
> ...
> +- com.acme:test-framework:jar:1.0.0:test (scope not updated to compile)
> The plugin resolves the conflict properly! The scope remains 'test', it's not 
> set to 'compile'.
> I detected this problem with versions 3.0.3 and 3.0.2. It might be present in 
> other versions too but I didn't bother to check any more versions.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to