0

I used maven-dependency-plugin plugin to unpack-dependencies .

I can see unpacked jars (those needed at compile stage) under target/dependency when run

mvn dependency:unpack-dependencies

But instead if I run

mvn clean install

I get compilation errors .

How could I let know maven that these unpacked jars to be used when compiling and installing ?

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>

                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeGroupIds>com.group</includeGroupIds>
                            <includeArtifactIds>zippedArtifact</includeArtifactIds>

                            <includes>x.jar,y.jar</includes>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
nish1013
  • 3,658
  • 8
  • 33
  • 46

1 Answers1

0

If you are just declaring an ordinary code dependency, just declare a dependency. Don't use any plugin at all. Just say,

<dependency>
   <groupId>...</groupId>
   ...
</dependency>

Maven will add that jar to your classpath. You don't need to unpack it.

If someone has really published a Maven artifact containing multiple jar files of binaries, Maven has no instant solution. You will need a separate Maven module that unpacks them with the dependency plugin and then uses the 'attach' option of the build helper plugin to turn each one into an artifact with a classifier, and then declare dependencies on them. It might be easier to just republish these individual jars to your local repository manager under their own coordinates.

If you need to pull other things out of a resource somewhere, like data files or additional source code, combine the dependency plugin with the build helper maven plugin. This plugin has goals to add additional source or resource directories that you've created with some other plugin.

If you need to combine your dependencies into your own jar file for some reason, see the Maven Shade Plugin. I suspect that the android plugin ecosystem has a better solution to get your dependencies to travel with your code, but if not, shade is there.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • I need to use jars, and what is the use of maven-dependency-plugin if it is still have to go with sources only? – nish1013 Oct 14 '13 at 12:35