[ 
https://jira.codehaus.org/browse/MNG-5082?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=324057#comment-324057
 ] 

Robert Balazsi edited comment on MNG-5082 at 4/24/13 6:09 AM:
--------------------------------------------------------------

I think I've managed to fix the problem, I attached a patch.

The method "MojoExecutor.execute(MavenSession session, List<MojoExecution> 
mojoExecutions, ProjectIndex projectIndex)" is called for every plugin to be 
executed. However, the method collected the dependencies for the entire 
lifecycle, not just the current phase. So before the "compile" phase, the 
library dependency ("some-lib" in the issue description) would be satisfied by 
the "maven-install-plugin" in the "validate" phase. However, it is attempted to 
be resolved beforehand (at the beginning of the lifecycle).

I solved it by rewriting the execute method so that the 
"newDependencyContext()" method would be called for every MojoExecution object, 
instead of only once for the list of MojoExecution objects.
I'm not sure how to write unit/integration tests, though, as the scenario uses 
the "maven-install-plugin", I appreciate any suggestions. All of the current 
tests pass, of course.

This is my first contribution, I hope that it turns out to be useful. :-)
                
      was (Author: rbalazsi):
    I think I've managed to fix the problem, I attached a patch.

The method "MojoExecutor.execute(MavenSession session, List<MojoExecution> 
mojoExecutions, ProjectIndex projectIndex)" is called for every plugin to be 
executed. However, the method collected the dependencies for the entire 
lifecycle, not just the current phase. So before the "compile" phase, the 
library dependency ("some-lib" in the issue description) would be satisfied by 
the "maven-install-plugin" in the "validate" phase. However, it is attempted to 
be resolved beforehand (at the beginning of the lifecycle).

I solved it by rewriting the execute method so that the 
"newDependencyContext()" method would be called for every MojoExecution object, 
instead of only once for the list of MojoExecution objects.
I'm not sure how to write unit/integration tests, though, as the uses the 
"maven-install-plugin", I appreciate any suggestions. All of the current tests 
pass, of course.

This is my first contribution, I hope that it turns out to be useful. :-)
                  
> Regression: Could not resolve dependencies for project
> ------------------------------------------------------
>
>                 Key: MNG-5082
>                 URL: https://jira.codehaus.org/browse/MNG-5082
>             Project: Maven 2 & 3
>          Issue Type: Bug
>          Components: Dependencies
>    Affects Versions: 3.0.3
>            Reporter: Florian Brunner
>            Priority: Blocker
>         Attachments: MNG-5082-maven-core.patch
>
>
> Sometimes, when you need a jar, which is not available from a repository, and 
> for some reason you don't want to deploy it to the corporate repository 
> (yet), you can do something like this:
> {code:xml}
>          <build>
>               <plugins>
>                         ...
>                       <plugin>
>                               <artifactId>maven-install-plugin</artifactId>
>                               <executions>
>                                       <execution>
>                                               <id>some-lib</id>
>                                               <phase>validate</phase>
>                                               <goals>
>                                                       
> <goal>install-file</goal>
>                                               </goals>
>                                               <configuration>
>                                                       
> <file>lib/some-lib-1.1.jar</file>
>                                                       
> <groupId>org.someorg.somelib</groupId>
>                                                       
> <artifactId>some-lib</artifactId>
>                                                       <version>1.1</version>
>                                                       
> <packaging>jar</packaging>
>                                               </configuration>
>                                       </execution>
>                               </executions>
>                       </plugin>
>                       ...
>               </plugins>
>       </build>
> {code}
> And then you can declare a dependency on this lib like this:
> {code:xml}
>          <dependencies>
>                 ...
>               <dependency>
>                       <groupId>org.someorg.somelib</groupId>
>                       <artifactId>some-lib</artifactId>
>                       <version>1.1</version>
>               </dependency>
>               ...
>       </dependencies>
> {code}
> This worked fine with {{Maven 2.2.1}} but not with {{Maven 3.0.3}} -> 
> regression!
> {noformat}
> Error message:
> [INFO] BUILD FAILURE
> [INFO] 
> ------------------------------------------------------------------------
> [INFO] Total time: 0.951s
> [INFO] Finished at: Thu Apr 28 15:53:15 BST 2011
> [INFO] Final Memory: 4M/121M
> [INFO] 
> ------------------------------------------------------------------------
> [ERROR] Failed to execute goal on project myproject: Could not resolve 
> dependencies for project someGroupId:someArtifactId:jar:0.1-SNAPSHOT: Could 
> not find artifact org.someorg.somelib:some-lib:jar:1.1 in nexus (<nexus url>) 
> -> [Help 1]
> [ERROR] 
> {noformat}
> There is a work-around, which at least works in some cases:
> {noformat}
> mvn clean validate
> mvn install
> {noformat}
> Some notes on this work-around:
> - install should call validate (which it does, but apparently with some 
> side-effects). It should not be necessary to call validate explicitly.
> - "mvn clean validate install" does not work! It shouldn't matter if you call 
> "mvn clean validate install" or "mvn clean validate" and "mvn install". Both 
> should have the same result.
> - I currently don't see a way to specify in Jenkins/ Hudson to first execute 
> "clean validate" and then "install" -> broken build on continuous integration 
> server which has to be fixed manually
> - This work-around breaks the Maven way, because you cannot simply go to a 
> project anymore and just call "mvn clean install" to build it.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to