How to add local jar to fat jar as a dependency using maven?

Viacheslav Shalamov :

I'm trying to build a fat jar to use it in some other place.
I use maven assembly plugin for that:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>

    </configuration>
    <executions>
        <execution>
            <id>assemble-all</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Among my dependencies I have a local jar dependency, which I can't refuse:

<dependency>
    <groupId>com.example</groupId>
    <artifactId>library</artifactId>
    <version>1.0.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/my-jar.jar</systemPath>
</dependency>

But this jar is on included to the final fat jar which I create with mvn package.
What is the best way to include my local jar to fat jar as a dependency?

UPD.
There are some related questions, but they do not answer the question completely:
add jar to the maven local repository before build
maven-assembly-plugin doesn't add dependencies with system scope

Essex Boy :

Easier to use the shade plugin:

Parent project:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.greg</groupId>
  <artifactId>fat-jar</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>library-jar</module>
    <module>final-jar</module>
  </modules>

</project>

Library project:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <artifactId>fat-jar</artifactId>
    <groupId>com.greg</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>library-jar</artifactId>
  <dependencies>
    ....
  </dependencies>

  <build>
  </build>
</project>

Final jar with dependency to library, under the same parent:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>fat-jar</artifactId>
        <groupId>com.greg</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>final-jar</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.greg</groupId>
            <artifactId>library-jar</artifactId>
            <version>${project.version}</version>
        </dependency>
          ...
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.greg.App</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to find the usage of a jar imported by maven dependency?

From Java

Maven dependency to jar in Nexus

From Java

How to add local project (not jar) as a dependency to a Maven project

From Java

How to make a "fat jar" of a Maven project?

From Java

Optional jar inclusion in fat jar in maven plugin

From Java

How to specify "sources" JAR for local JAR dependency?

From Java

How to add local jar files to a Maven project?

From Java

Maven: add a dependency to a jar by relative path

From Java

How to add local .jar file dependency to build.gradle file?

From Java

Maven: Add local dependencies to jar

From Java

maven dependency - which dependency is using unwanted jar?

From Java

How to download maven dependency as *.jar file?

From Java

Why maven cannot add my dependency to jar?

From

Building a fat jar using maven

From Java

How to get path to dependency jar with maven

From Java

How to deal with fat jar dependency

From Java

Renaming a fat jar with Maven

From Java

<Maven>How to add class files as dependency (not jar) in maven project?

From Dev

Eclipse - How to add a project as a Maven dependency to another, instead of adding as a jar?

From Dev

How to create a fat jar?

From Dev

add jar to the maven local repository before build

From Dev

How to force adding provided dependency to fat jar using sbt-assembly plugin?

From Dev

Fat jar is missing with junit dependency

From Dev

add custom jar to maven local repository

From Dev

Maven won't add local dependency to target jar

From Dev

how to add jar dependency in maven?

From Dev

How to add a local jar dependency to another dependency in gradle?

From Dev

Maven: How to package local jar into final jar?

From Dev

Maven assembly plugin: dependency jars are not included, fat jar without jars

Related Related

  1. 1

    How to find the usage of a jar imported by maven dependency?

  2. 2

    Maven dependency to jar in Nexus

  3. 3

    How to add local project (not jar) as a dependency to a Maven project

  4. 4

    How to make a "fat jar" of a Maven project?

  5. 5

    Optional jar inclusion in fat jar in maven plugin

  6. 6

    How to specify "sources" JAR for local JAR dependency?

  7. 7

    How to add local jar files to a Maven project?

  8. 8

    Maven: add a dependency to a jar by relative path

  9. 9

    How to add local .jar file dependency to build.gradle file?

  10. 10

    Maven: Add local dependencies to jar

  11. 11

    maven dependency - which dependency is using unwanted jar?

  12. 12

    How to download maven dependency as *.jar file?

  13. 13

    Why maven cannot add my dependency to jar?

  14. 14

    Building a fat jar using maven

  15. 15

    How to get path to dependency jar with maven

  16. 16

    How to deal with fat jar dependency

  17. 17

    Renaming a fat jar with Maven

  18. 18

    <Maven>How to add class files as dependency (not jar) in maven project?

  19. 19

    Eclipse - How to add a project as a Maven dependency to another, instead of adding as a jar?

  20. 20

    How to create a fat jar?

  21. 21

    add jar to the maven local repository before build

  22. 22

    How to force adding provided dependency to fat jar using sbt-assembly plugin?

  23. 23

    Fat jar is missing with junit dependency

  24. 24

    add custom jar to maven local repository

  25. 25

    Maven won't add local dependency to target jar

  26. 26

    how to add jar dependency in maven?

  27. 27

    How to add a local jar dependency to another dependency in gradle?

  28. 28

    Maven: How to package local jar into final jar?

  29. 29

    Maven assembly plugin: dependency jars are not included, fat jar without jars

HotTag

Archive