2

I am literally trying to do exactly this:

http://maven.apache.org/plugins/maven-dependency-plugin/usage.html#The_dependency:build-classpath_mojo

What's amazing is that after finding an explicit example of exactly what I want Maven to do.. I still can't get it to work.

From the command line, I can run ... mvn -Dmdep.outputFile=classpath.txt dependency:build-classpath ... which does indeed produce a file called classpath.txt with the information I'd like.

I would like to be able to issue a command like "mvn compile" and have the production of this classpath.txt file be a part of that process. The example provided at the link above associates it with generate-sources, which to my understanding should suffice.

When executing a command like "mvn compile" with this pom snippet below, nothing regarding the build-classpath goal seems to execute.

<build>
<pluginManagement>
  <plugins>      

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>

        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>

     </plugin>

     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.8</version>
      <executions>
       <execution>
        <id>build-classpath</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>build-classpath</goal>
        </goals>
         <configuration>
            <outputFile>myfile.txt</outputFile>
            <mdep.outputFile>myFile1.txt</mdep.outputFile>
            <ihavenoidea>whatgoeshere</ihavenoidea>
         </configuration>
       </execution>
     </executions>
    </plugin>
  </plugins>
 </pluginManagement>
</build>

And here is what I end up with:

$ mvn compile
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building someproj 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ someproj ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ someproj ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.600s
[INFO] Finished at: Fri Jan 31 14:05:29 CST 2014
[INFO] Final Memory: 9M/156M
[INFO] ------------------------------------------------------------------------

$ ls 
bin     html        log     pom.xml     resources   sql     src     target      test-output wwwroot
Lance
  • 23
  • 1
  • 4
  • StackExchange is amazing. I know this because moments after posting my problem, I solved it on my own. :| Removing the "PluginManagement" element solves the issue, but I'm not entirely sure why. Any help? – Lance Jan 31 '14 at 20:12
  • Welcome to StackOverflow! Please add an answer to your question and accept it as the answer. That way, people searching for your problem will find your solution as well. – Steve H. Jan 31 '14 at 20:32

2 Answers2

1

Your plugin definition is inside <pluginManagement>, which means that when you will declare a "real" execution of that plugin inside a pom that has this pom as parent (or this pom itself), it will use that configuration.

This is generaly a good idea to use <pluginManagement> when a common configuration has to be applied on multiple execution, through multiple modules in the same global project.

Here, I would personally keep the compiler plugin inside <pluginManagement>, as you probably always want that plugin to be configured like this, but I woul move the dependency-plugin inside the <plugins> section (outside the <pluginManagement> section, well yes, this can be confusive...)

Tome
  • 3,234
  • 3
  • 33
  • 36
  • That was exactly it. pluginManagement was making maven treat my addition more like a template, apparently for child poms. There is also another similar thread here: http://stackoverflow.com/questions/10483180/maven-what-is-pluginmanagement Thanks for the help. – Lance Jan 31 '14 at 20:58
0

You may think of <pluginManagement> as a kind of template. It's often used in parent POMs to define a common configuration. Only plugins in <build><plugins> are included in the build.

That said, Maven does do some "magic" depending on the packaging type. I answered a similar question here.

Community
  • 1
  • 1
user944849
  • 14,524
  • 2
  • 61
  • 83