Unzip dependency in maven
Asked Answered
S

2

30

I have the following dependency in maven

<dependency>
  <groupId>org.hyperic</groupId>
  <artifactId>sigar-dist</artifactId>
  <version>1.6.5.132</version>
  <type>zip</type>
</dependency>

This creates sigar-dist-1.6.5.132.zip in my repository. I have seen this question here, however I still can't make it work.

How can I unzip the sigar-dist.zip and place the content in a directory in my project? What is the mvn call I have to do to make it work?

Sternutation answered 22/3, 2011 at 8:42 Comment(0)
S
48

You can do it with dependencies:unpack-dependencies:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <id>unpack-sigar</id>
        <phase>package<!-- or any other valid maven phase --></phase>
        <goals>
          <goal>unpack-dependencies</goal>
        </goals>
        <configuration>
          <includeGroupIds>org.hyperic</includeGroupIds>
          <includeArtifactIds>sigar-dist</includeArtifactIds>
          <outputDirectory>
             ${project.build.directory}/wherever/you/want/it
             <!-- or: ${project.basedir}/wherever/you/want/it -->
          </outputDirectory>
        </configuration>
      </execution>
    </executions>
</plugin>

Reference:

Shahjahanpur answered 22/3, 2011 at 8:51 Comment(4)
Thanks for quick response. I tried this, and after dependency:unpack-dependencies and mvn install I get [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] 'unpack-sigar' was specified in an execution, but not found in the pluginSternutation
Is this unpacked-code compiled and linked to the project instead of the original dependency ? Or is just unpackaged in order you can see the code ?Squiggle
Better to mention, this plugin tag should be under build tag.Peppi
@yucer, it depends on the phase to which you bind unpack-dependencies goal and the outputDirectory for the unpacked content. And I don't think there is "unlink" performed for the original dependency. If you wish not to make it transitive you can add <scope>provided</scope> to the reference.Anticathode
P
4

just a follow up on answer from @Sean Patrick Floyd

this is my final pom.xml to download and unpack tomcat

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>org.koushik.javabrains</groupId>
    <artifactId>tomcat</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>tomcat</name>

    <properties>
        <tomcat.version>8.0.27</tomcat.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>unpack-tomcat</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>org.apache.tomcat</includeGroupIds>
                            <includeArtifactIds>tomcat</includeArtifactIds>
                            <outputDirectory>
                                ${project.build.directory}
                                <!-- or: ${project.basedir}/wherever/you/want/it -->
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat</artifactId>
            <version>${tomcat.version}</version>
            <type>zip</type>
        </dependency>
    </dependencies>
</project>
Publisher answered 5/10, 2015 at 20:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.