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.

2

1 Answer 1

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> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.