Maven 2 & 3

@requiresDependencyResolution in process-classes post compile

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Not A Bug
  • Affects Version/s: 2.0
  • Fix Version/s: None
  • Labels:
    None
  • Complexity:
    Expert
  • Number of attachments :
    0

Description

I was looking back into some plugins I had written a while back and ran across an oddity.

it appears that when using a plugin in the process-classes phase, after the compiler plugin has done its thing, the @requiresDependencyResolution javadoc flag will toggle the presense of dependencies that are scoped to provided in the dependencies section when calling project.getCompileClasspathElements(); (a difference of 80 vs 24 when not using the flag and then using it)

this are two snippits of code from the plugin

/**

  • A plugin for generating * java file containing all the classes in a src tree.
    *
  • @goal generate
  • @requiresDependencyResolution
  • @description Functions Generator plugin
  • @author jesse <jesse@g.com>
    */

List classpathFiles = project.getCompileClasspathElements();

URL[] urls = new URL[classpathFiles.size() + 1];

getLog().debug("" + classpathFiles.size());

for (int i = 0; i < classpathFiles.size(); ++i) { getLog().debug((String)classpathFiles.get(i)); urls[i] = new File((String)classpathFiles.get(i)).toURL(); }

urls[classpathFiles.size()] = new File( buildDirectory + "/classes" ).toURL();

URLClassLoader ucl = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader());

being used with the following plugin declaration:

<plugin>
<groupId>gallup.maven</groupId>
<artifactId>services-provider-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<fullyQualifiedFileName>com/g/util/ServiceProvider.java</fullyQualifiedFileName>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>


analyzing the debug output when I run the plugin without the @requiresDependencyResolution I get 80 dependencies and it builds out the classloader correctly..

but if I add the @requiresDependencyResolution statement I go down to 24 dependencies being put into the classloader...and the discrepency corresponds to the presense of the <scope>provided</scope> statement.

Issue Links

Activity

Hide
Grégory Joseph added a comment -

I'm running into a similar issue with MOJO-239 :
My mojo is bound to the generate-sources phase, and if it adds a source root with project.addCompileSourceRoot, then the compiler plugin looses his mind and can't find some dependency(ies). On the other hand, if I don't add a source root (keepJava=false in the mojo, which is the default), then everything is fine.

Show
Grégory Joseph added a comment - I'm running into a similar issue with MOJO-239 : My mojo is bound to the generate-sources phase, and if it adds a source root with project.addCompileSourceRoot, then the compiler plugin looses his mind and can't find some dependency(ies). On the other hand, if I don't add a source root (keepJava=false in the mojo, which is the default), then everything is fine.
Hide
Benjamin Bentmann added a comment -

@requiresDependencyResolution is equivalent to @requiresDependencyResolution runtime and runtime scope does not include provided scope. Plugins get what they ask for, not more.

Show
Benjamin Bentmann added a comment - @requiresDependencyResolution is equivalent to @requiresDependencyResolution runtime and runtime scope does not include provided scope. Plugins get what they ask for, not more.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
3h
Original Estimate - 3 hours
Remaining:
3h
Remaining Estimate - 3 hours
Logged:
Not Specified
Time Spent - Not Specified