Build Thirdparty Examples

This page provides examples of how to use the build-thirdparty goal.

Basic Example

This example shows how to build a thirdparty directory structure (for use in a buildmagic project) using dependencies downloaded from a maven repository.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.jboss.maven.plugins</groupId>
        <artifactId>maven-buildmagic-thirdparty-plugin</artifactId>
        <executions>
          <execution>
            <id>build-thirparty</id>
            <goals>
              <goal>build-thirparty</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <librariesEnt>${project.build.directory}/libraries.ent</librariesEnt>
              <includedScopes>
                <scope>compile</scope>
              </includedScopes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  <dependencies>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
    </dependency>
  </dependencies>
  ...
</project>

There are three dependencies listed in this project: ant, junit, and log4j. After running "mvn generate-resources", the above configuration will generate a directory structure similar to the following.

 
  myproject
  |
  +-target/
    | 
    +-ant/
    | |
    | +-component-info.xml
    | |
    | +-lib/
    |   |
    |    +-ant.jar
    |
    +-log4j
    | |
    | +-component-info.xml
    | |
    | +-lib/
    |   |
    |    +-log4j.jar

Notice that junit is not included in the thirdparty directory. This is because the above configuration specified that we only wanted to include dependencies in the "compile" scope, and junit was defined in the test scope

Mapping dependencies to custom locations

Sometimes you may want to download maven dependencies into non-default locations in the thirdparty directory. This can be accomplished using a the mappedDependencies configuration. Using the same dependency configuration as the previous example, you could do something like this:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.jboss.maven.plugins</groupId>
        <artifactId>maven-buildmagic-thirdparty-plugin</artifactId>
        <executions>
          <execution>
            <id>build-thirparty</id>
            <goals>
              <goal>build-thirparty</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}</outputDirectory>
              <librariesEnt>${project.build.directory}/libraries.ent</librariesEnt>
                  <mappedDependencies>
                    <dependency>
                      <groupId>ant</groupId>
                      <artifactId>ant</artifactId>
                      <mapping>
                        <componentId>my.ant</componentId>
                        <artifactId>some-new-name</artifactId>
                      </mapping>
                      </dependency>
                    </mappedDependencies>
              </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

The mapping configuration will download the ant dependency to the new location and the new file name.

 
  myproject
  |
  +-target/
    | 
    +-my/
    | |
    | +-ant/
    |   |
    |   +-component-info.xml
    |   |
    |   +-lib/
    |     |
    |     +-some-new-name.jar

Copying source jars

The build-thirdparty goal has the option to copy source jars from the local maven repository into the thirdparty repository. In order for this to be used, the source jars must be downloaded by something like the maven dependency plugin .

For example, the sources goal of thedependency plugin can be configured to automatically run prior to the build-thirdparty goal as in the following example.

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>2.0</version>
        <executions>
          <execution>
            <id>download-sources</id>
            <goals>
              <goal>sources</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.jboss.maven.plugins</groupId>
        <artifactId>maven-buildmagic-thirdparty-plugin</artifactId>
        <executions>
          <execution>
            <id>build-thirparty</id>
            <goals>
              <goal>build-thirparty</goal>
            </goals>
            <configuration>
              <copySources>true</copySources>
            </configuration>
          </execution>
        </executions>
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>