Hi Ashish,
the dependencies of the project-pom are not part of the maven classpath.
That means that your plugin does not run in a JVM where that jars have
been loaded. Your plugin will run having its own dependencies loaded
(those of plugin-pom), not those of the project that is currently under
build.

I don't know if there is a way to declare a plugin like "runs in the
classpath of the project, not its own", anyway :



If you just need to SEE which dependencies are declared, and also
eventually find the jars and parse them to find specific resources and
so on, you can use the project to find them :
- Declare in your plugin you want access to the project

    /**
     * The maven project.
     *
     * @parameter expression="${executedProject}"
     * @required
     * @readonly
     */
    private MavenProject project;

- Access project.getArtifacts() to see which dependencies project-pom
declares, here you can see if project-pom has a certain dependency or
doesnt.
- You can even find the file:// urls to the jar files of those
dependencies in the local repository:

            Set artifacts = project.getArtifacts();
            for (Iterator iterator = artifacts.iterator();
iterator.hasNext();) {
                Artifact art = (Artifact) iterator.next();
                urls.add(art.getFile().toURI().toURL());
            }

Now you can use the file urls to open the jars using ZipFile and check
for the presence of specified classes, or to read files inside like
deployment descriptors and the like.



If you need to RUN those classes (like be able to invoke methods on them
and so on), then you need to do some classloader magics in your plugin
to load them. The simplest form is to setup an URLClassLoader, feed it
with the urls obtained with the previous snippet, and then execute your
code in that classloader.

For example, the jetty:run goal sets up a classloader using dependencies
from the project-pom and then runs the servlets inside that classloader,
so that all the dependencies are available to running code. ClassLoader
stuff can be hard to setup properly, so take the time to read all
relevant stuff about how to run classes in a different classloader
before hacking code .. it CAN get quite frustrating.



Hope this helps,
Simone

Sahni, Ashish wrote:
> Hi,
>  
> I have a custom maven plugin that does not seem to be picking up a
> compile time dependency. The project structure
> is something like
>  
> super-pom: 
>     defines the plugin build usage - goal/phase(generate-sources)
>  
> project-pom: 
>     inherits from super-pom.
>     defines a default(compile scope) dependency (called xyz-1.0)
>  
> When the custom maven plugin is invoked via project-pom, it does not
> contain xyz-1.0.jar in its classpath.
> What am I missing here ? How do I get a compile time dependency defined
> in a project pom in the classpath
> of the custom plugin ?
>  
> Thanks
> Ashish
>  
>
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to