Question

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?

Was it helpful?

Solution 2

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...

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top