0

I'm working on a plugin for Talend Open Studio; the component architecture of that platform needs that all external JARs are declared in a component-descriptor XML file in a form like:

<IMPORT MODULE="commons-collections-3.2.1.jar" NAME="commons-collections-3.2.1" 
    REQUIRED="true"/>

I use the Maven dependency plugins to manage all these external JARs

Is there a way to get all the dependency names in a list or something? This way can I be able to build the required strings (using an antcontrib task, perhaps), fill a ${parameter} and finally add it to XML file using maven-replacer-plugin?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Gabriele B
  • 2,665
  • 1
  • 25
  • 40
  • Use the dependency plugin? You can generate a classpath, a dependency tree, etc. – Dave Newton Nov 03 '12 at 19:12
  • Ok but, for ex., i don't know how to vuild a ${parameter} from, let's say, a classpath string... – Gabriele B Nov 03 '12 at 20:50
  • Split it and use any of a zillion XML/templating/whatever mechanisms to generate the XML? Create a property file that's understood by whatever is using that XML file? Etc. – Dave Newton Nov 03 '12 at 21:57

2 Answers2

3

The simplest solution is to use the maven-dependency-plugin via the buld-classpath goal. This goal can be given supplemental parameters to put the result into a file like:

mvn dependency:build-classpath -Dmdep.outputFile=classpath.out
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • If using this directly on the command line then you will need to use `mdep.outputFile` not `outputFile` – Dennis Apr 08 '15 at 14:19
0

Ok, I partly resolved this way that should works with some limitations:

<plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.6</version>
        <dependencies>
            <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
            <exclusions>
                <exclusion>
                    <groupId>ant</groupId>
                    <artifactId>ant</artifactId>
                </exclusion>
            </exclusions>
            </dependency>
            <dependency>
                <groupId>ant</groupId>
                <artifactId>ant-nodeps</artifactId>
                <version>1.6.5</version>
            </dependency>
        </dependencies>
        <executions>
          <execution>
            <phase>package</phase>
            <id>copy-resources</id>
            <configuration>
              <exportAntProperties>true</exportAntProperties>
              <tasks>
                <!-- add the ant tasks from ant-contrib -->
                <taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath"/>
                <var name="import.set" value=""/> 
                <for param="file">
                    <path>
                        <fileset dir="${project.build.directory}" includes="*.jar"/>
                    </path>
                    <sequential> 
                        <var name="basename" unset="true"/> 
                        <basename file="@{file}" property="basename"/>
                        <var name="filenames" value="${basename}"/>
                        <var name="import.clause" value='&lt;IMPORT MODULE="${filenames}" NAME="${filenames}" REQUIRED="true"/&gt;'/>
                        <var name="import.set" value="${import.clause}${line.separator}${import.set}" />
                    </sequential> 
                </for>
                <property name="import.jar" value="${import.set}"/> 
                <echo>${import.jar}</echo>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

Still some problems: even if exportAntProperties is set to true, the property ${import.jar} is still not available outside ant taska in other maven goals, while if i switch to maven-antrun-plugin 1.7 version, a "Error executing ant tasks: org.apache.tools.ant.launch.Locator.fromJarURI(Ljava/lang/String;)Ljava/lang/String;" exception is thrown. Still no clues...

Gabriele B
  • 2,665
  • 1
  • 25
  • 40