Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add local external jar - should not point at files within the project directory

Tags:

maven

In my maven project I use custom external my-custom-external jar like this:

pom.xml

<dependencies>
    <dependency>
        <groupId>com.myproject</groupId>
        <artifactId>my-custom-external</artifactId>
        <version>1.0-SNAPSHOT</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/libs/my-custom-external-1.0-SNAPSHOT.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

I success build project my mvn verify but in console I has warning:

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.myproject:prj_1:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.systemPath' for com.myproject:my-custom-extneral:jar should not point at files within the project directory, ${project.basedir}/libs/my-custom-extneral-1.0-SNAPSHOT.jar will be unresolvable by dependent projects @ line 62, column 25
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
like image 890
Alexei Avatar asked Mar 15 '19 13:03

Alexei


People also ask

Can we add external jar in Maven project?

Approach 2: Include jar as part of the maven project. In this approach you need to first create a folder in your maven project & add your external jar file. Once the jar file is added, include the jar file in your pom using following notation.

How do I import a Maven project into another?

Right-click the utility project, and select Maven>Add Dependency. Type a dependency name in the Enter groupID… field (e.g., commons-logging) to search for a dependency. Select the dependency, and click OK.


Video Answer


2 Answers

you can use ${pom.basedir} to replace ${project.basedir}

like image 156
waitingmyself Avatar answered Oct 20 '22 15:10

waitingmyself


It is just a warning and you are okay to do this as long as it is used only in this project as it won't be visible for the dependent projects.

You can consider below two options for doing it right

  1. Install the 3rd party jar to your local repository and reference it just like any other dependency. Refer to this link for more details on installing the library
  2. If you want to refer it from your project, then add your project libs folder as a repository as shown below

    <repositories>
        <repository>
            <id>localrepository</id>
            <url>file://${project.basedir}/libs</url>
        </repository>
        .
        .
        .
        .
    </repositories>
    

Hope this helps

like image 36
Prasann Avatar answered Oct 20 '22 14:10

Prasann