On 11/09/2011 12:00 AM, Jason van Zyl wrote:
today we learned about the AbstractMavenLifecycleParticipant
Here's an example of how it works for matching the dependencies specified from
a 3rd party source to the reactor.
[...]
It's using JSR330, but you can pull those out and use Plexus annotations if you
need it to work in the short term.
A standalone example I just got to work: create a jar-packaging project with
@Component(role=AbstractMavenLifecycleParticipant.class)
public class WhateverNameYouLike extends AbstractMavenLifecycleParticipant {
@Requirement private Logger log;
@Override public void afterProjectsRead(MavenSession session) throws
MavenExecutionException {
for (MavenProject p : session.getProjects()) {
log.info("tweaking " + p);
Dependency d = new Dependency();
d.setGroupId("org.apache.commons");
d.setArtifactId("commons-io");
d.setVersion("1.3.2");
p.getDependencies().add(d);
}
}
}
built with
<build>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.5.5</version>
<executions>
<execution>
<goals>
<goal>generate-metadata</goal>
</goals>
<id>generate-metadata</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0.3</version>
</dependency>
</dependencies>
Now create a quickstart project and edit the main method to say:
System.out.println(org.apache.commons.io.EndianUtils.swapInteger(1));
Once you tell it
<build>
<extensions>
<extension>
...coordinates as for first project...
</extension>
</extensions>
</build>
then it will compile (under 3.0.3) despite not itself declaring a dep on
commons-io.
BTW I was not successful in using @javax.inject.Singleton in place of
@Component.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
For additional commands, e-mail: dev-h...@maven.apache.org