Dante
Dante

Reputation: 297

I have no transitive dependencies when use custom jar file

I have created own .jar file using maven. It requires some libs. All of them are added in pom.xml of custom .jar, but I have a problem! When i adding my jar to project no required libs are adding to Maven Dependencies of project. And i dont want to create jar with dependencies. I belive that it is bad solution to download all required libs in jar. I am new to maven, so please help to find solution.This is the pom.xml of my jar:

<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>ReportBuilder</groupId>
    <artifactId>ReportBuilder</artifactId>
    <version>0.0.1</version>
    <packaging>jar</packaging>
    <name>ReportBuilder</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.7</version>
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>0.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Upvotes: 0

Views: 1300

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62350

With your current specification, using <scope>system</scope> and specifying the path to the jar file, you only include a single jar without any dependencies. Maven cannot know about dependencies because the jar file itself does not contain this information and maven cannot access pom.xml (that was used to build the jar file) via this configuration.

Transitive dependencies can only be resolved, if maven has access to dependency information specified in pom.xml of the dependent jar. To make it accessible, you need to install the dependent project into you local maven repository (located in ~/.m2/repository). You can achieve this by using maven goal install. For example:

mvn -DskipTests clean install

The goal install is executed after package and will copy the built jar file and dependency meta information (extracted from pom.xml) into your local maven repository.

After you have installed your dependent project, you can include it into any other project like a regular dependency:

<dependency>
  <groupId>ReportBuilder</groupId> 
  <artifactId>ReportBuilder</artifactId>
  <version>0.0.1</version>
</dependency>

Maven looks up all dependencies in local repository. As you installed it, maven will find it -- including information about transitive dependencies which can be resolved now.

Upvotes: 3

Related Questions