Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven copy dependecies not working

This question ha sbeen asked but none of the solutions worked for me so:

I want to copy my jars which are specified through the dependency tags in the build of POM.xml:

<dependency>
...
</dependency>

into a folder like target/lib

pom.xml:

<build>
    <defaultGoal>install</defaultGoal>
    <directory>${basedir}/target</directory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.googlecode.addjars-maven-plugin</groupId>
                <artifactId>addjars-maven-plugin</artifactId>
                <version>1.0.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>add-jars</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/my-repo</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <classpathPrefix>lib/</classpathPrefix>
                            <addClasspath>true</addClasspath>
                            <mainClass>Swapper</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <includeScope>runtime</includeScope>
                            <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Like i said, nothing is copied at all. But according to some Q&A on this portal it should work.

Any ideas?

like image 694
Gobliins Avatar asked Nov 30 '22 10:11

Gobliins


1 Answers

You are declaring your plugins in your <pluginManagement> section. This is all well and good, but if want them to execute you need to declare them outside the <pluginManagement> section:

<build>
  <pluginManagement>
     ...
  </pluginManagement>
  <plugins>
    <plugin>
     <artifactId>addjars-maven-plugin</artifactId>
    </plugin>
    <plugin>
     <artifactId>maven-jar-plugin</artifactId>
    </plugin>
    <plugin>
     <artifactId>maven-dependency-plugin</artifactId>
    </plugin>
  </plugins>
</build>

Think of <pluginManagement> in the same way you think of <dependencyManagement>, but for plugins.

like image 115
Daniel Avatar answered Dec 04 '22 12:12

Daniel