I noticed this too. The main reason is the plexus container does not know anything about the maven sessions. Maven sessions and other things are no valid plexus components (in the meaning they do not prefer to be a singleton). However the current solution for me was to have some little wrapper that is able to inject maven session on request. The magic happens in org.apache.maven.plugin.PluginParameterExpressionEvaluator.
Whenever receiving an object from plexus that requires maven session and others you should not try to receive it via @required/@Requirement directly. Instead access the plexus container and use this expression evaluator. It does everything that is normally injected to mojos and their requirements only. See https://github.com/php-maven/maven-php-plugin/blob/master/branches/2.0-SNAPSHOT/maven-php-core/src/main/java/org/phpmaven/core/ComponentFactory.java#L175 for an example. Whatever you are doing there may be other solutions. Maven itself has some utilities to receive a plugin in the correct way. The above scenario is only related with scenarios you mix up with "the maven way" and "the plexus way". And maybe I was totally wrong to write this utility :) However if there is need it is possible to merge my configurationfactory utility class to a more common maven project and push it to central. On Wed, Aug 15, 2012 at 7:31 AM, Kinai User <[email protected]> wrote: > Hi Martin, > > Plugin A has several executions defined with different configurations. > Here's an example of such a configuration (from the <build><plugins>-part): > > <execution> > <id>aspectJ-weaving-execution</id> > <phase>compile</phase> > <goals> > <goal>executePlugin</goal> > </goals> > <configuration> > <pluginExecutionIds> > <pluginExecutionId>aspectJ-weaving</pluginExecutionId> > </pluginExecutionIds> > <pomPackagings> > <pomPackaging>jar</pomPackaging> > <pomPackaging>war</pomPackaging> > <pomPackaging>ejb</pomPackaging> > </pomPackagings> > <pomProperties> > <property> > <name>doAspectJWeaving</name> > <value>true</value> > </property> > </pomProperties> > </configuration> > </execution> > > Plugin A will check the current project to see whether it is of > pomPackaging > type jar/war or ejb or if the project contains the property > doAspectJWeaving > with the value true. If one of these conditions is met plugin A decides to > execute the <pluginExecutionId>aspectJ-weaving</pluginExecutionId>. > > Here's the configuration for the pluginExecution = aspectJ-weaving from the > <build><pluginManagement>-part: > <plugin> > > <groupId>org.codehaus.mojo</groupId> > <artifactId>aspectj-maven-plugin</artifactId> > <version>1.4</version> > <configuration> > <complianceLevel>1.5</complianceLevel> > <verbose>true</verbose> > <showWeaveInfo>true</showWeaveInfo> > <proceedOnError>false</proceedOnError> > <aspectLibraries> > <aspectLibrary> > <groupId>org.springframework</groupId> > <artifactId>spring-aspects</artifactId> > </aspectLibrary> > </aspectLibraries> > </configuration> > <executions> > <execution> > <id>*aspectJ-weaving*</id> > <goals> > <goal>compile</goal> > </goals> > </execution> > </executions> > </plugin> > > However plugin B needs access to the MavenProject or MavenSession instance > to retrieve some maven info but since these dependencies are not injected a > NullPointerException (or if @required was defined a missing parameter) will > be thrown. > > Beware that I used an example for Plugin B which is an existing plugin > where > we do not have the sources of. But this also holds for plugin that we > created ourselves. > > Any help appreciated. > > Regards, > Richard > > > > -- > View this message in context: > http://maven.40175.n5.nabble.com/MavenProject-MavenSession-not-injected-when-executing-plugin-from-a-plugin-tp5716570p5717095.html > Sent from the Maven - Users mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
