tags:

views:

93

answers:

3

I would like to place the names of the dependencies in a text file that is distributed inside a package that is built with Maven.

I am planning to use the maven assembly plugin to generate the tarball package, and use filtering to put the names in the text file.

The only problem is, I don't know how to reference the dependencies in the first place.

A: 

You can use the maven-dependency-plugin dependency:tree to output the tree of dependencies into a file.

lexicore
+5  A: 

You don't need to use filtering for that, use the Maven Dependency plugin and its a dependency:tree goal to display the dependency tree for this project. Set an output file with the... outputFile optional parameter. So the configuration might look like:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>tree</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>tree</goal>
            </goals>
            <configuration>
              <outputFile>${project.build.outputDirectory}/dep.txt</outputFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

Running the package phase would generate the dependency tree in target/classes/dep.txt and package it in the artifact. Adapt it to suit your needs.

Pascal Thivent
A: 

mvn dependency:resolve seems to be what you are looking for. Put following plugin configuration to your POM file:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>list-dependencies</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>resolve</goal>
        </goals>
        <configuration>
          <outputFile>dependencies.txt</outputFile>
        </configuration>
      </execution>
    </executions>
  </plugin>

It will produce file dependencies.txt with content similar to:

The following files have been resolved:
   am:amagent:jar:1.0:system
   am:amclientsdk:jar:1.0:system
   aopalliance:aopalliance:jar:1.0:compile
   asm:asm:jar:2.2.3:compile
   com.sun.jdmk:jmxtools:jar:1.2.1:compile
   com.sun.jmx:jmxri:jar:1.2.1:compile
   com.sun.xml.bind:jaxb-impl:jar:2.1.12:compile
   com.sun.xml.fastinfoset:FastInfoset:jar:1.2.2:compile
   com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.2:compile
   commons-lang:commons-lang:jar:2.3:compile
   commons-logging:commons-logging:jar:1.1:compile
   dom4j:dom4j:jar:1.6.1:compile
   javax.activation:activation:jar:1.1:provided
   javax.jms:jms:jar:1.1:compile
   javax.mail:mail:jar:1.4:compile
   javax.xml.bind:jaxb-api:jar:2.1:compile
   javax.xml.soap:saaj-api:jar:1.3:compile
   junit:junit:jar:4.4:test
   log4j:log4j:jar:1.2.15:compile
koppernickus