2
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
                <manifest>
                    <mainClass>com.company.Main</mainClass>
                </manifest>
            </archive>
        </configuration>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

The problem is I have some local dependencies I'd like to keep in the project.

I defined them in pom.xml like so:

    <dependency>
        <groupId>groupid</groupId>
        <artifactId>local</artifactId>
        <version>1.1</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/local-utilities-1.1.jar</systemPath>
    </dependency>

Now when I package the whole thing maven-assembly-plugin packs only dependencies that are automatically downloaded and available in repo... That's probably because those local JARs are available in compile phase, not in package phase (correct?).

How can I make this plugin include those dependencies as well? I tried changing <scope> to package and other phases, but apparently that's not allowed by Maven.

LetMeSOThat4U
  • 6,470
  • 10
  • 53
  • 93
  • See : http://stackoverflow.com/questions/2588502/maven-assembly-plugin-doesnt-add-dependencies-with-system-scope – Grzesuav Oct 21 '14 at 08:35
  • Start using a repository manager or use [Stephen Collony's plugin](https://github.com/stephenc/non-maven-jar-maven-plugin) which is a better solution than `system scope`. – khmarbaise Oct 21 '14 at 15:38

1 Answers1

2

You need to "manually" copy those dependencies so that the packager can include them.

<build>
        <pluginManagement>      
            <plugins>
                <!-- Ignore/Execute plugin execution -->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <!-- copy-dependency plugin -->
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[1.0.0,)</versionRange>
                                        <goals>
                                            <goal>copy-dependencies</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
           </plugins>
        </pluginManagement>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.4</version>
                <executions>
                           <execution>
                            <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                    </execution>

                </executions>
                <configuration>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                </configuration>
            </plugin>

            <plugin>
                <!-- creates one single JAR, run: mvn assembly:single | mvn install -->
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                            </execution>
                </executions>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>${mainClass}</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

        </plugins>

    </build>
Drejc
  • 14,196
  • 16
  • 71
  • 106