1

I am working on a multi-module maven project and have third party jar which isn't available in central or public repository, I also even don't want to place on public repo. I am providing following plugin directive in my parent pom to install jar in my local maven repository before its dependency is resolved in child project.

enter image description here

Now I provide dependency in child project as;

enter image description here

But I build the project, it successfully adds dependency in local maven repository (places third party jar in .m2 folder) but the at the same time it gives following error. Looks like, it searches this jar file in child projects libs folder as well, while I have already placed it on root (in myproject.parent/libs).

 Failed to execute goal org.apache.maven.plugins:maven-install-plugin:3.0.0-M1:install-file (install- 
 external-non-maven1-jar) on project myProject.core: The specified file 'C:\Users\myuser\git\MyProjectRepository\myproject.parent\myproject.core\libs\be-ixf-java-sdk-jar-with-dependencies.jar' not exists.

I already know scope and systemPath option but I don't want to use it for some reason. Kindly help in identifying what I am missing ?

touseefkhan4pk
  • 473
  • 4
  • 26

1 Answers1

1

The best approach that you could have if your project have a centralized maven repo like nexus setup is to have your third party library also added to the repo. Now , you are having the bin file added to your project and it's not preferable.

If you already have the required jar under your project code in like : libs\*, then why can't you refer the dependency directly in your pom.xml instead of having to install it in your local maven repo and then use it .

  <dependency>
      <groupId>anything</groupId>
      <artifactId>anything</artifactId>
      <version>anything</version>
      <scope>system</scope>
      <systemPath>${basedir}/lib/jar_name.jar</systemPath>
  </dependency>

providing the location of the dependency in your project directory should resolve it during build itself.Look at Maven System dependencies.

Since you do not want to change your current setup . Please bear in mind the following about maven pom structure :

Project Aggregation is similar to Project Inheritance. But instead of specifying the parent POM from the module, it specifies the modules from the parent POM. By doing so, the parent project now knows its modules, and if a Maven command is invoked against the parent project, that Maven command will then be executed to the parent's modules as well

So the maven-install-plugin execution that you added in main pom.xml might be getting triggered for all your modules because of this reason. You might want to move that to the module that you actually need this lib to be included in.Read maven doc.

Related : force Maven to copy dependencies into target/lib

Ananthapadmanabhan
  • 5,706
  • 6
  • 22
  • 39
  • I already know this solution. But I don't want to use it for some reason. – touseefkhan4pk May 25 '20 at 04:17
  • I have updated the answer.Please share your pom files for furthur analysis @touseefkhan4pk – Ananthapadmanabhan May 25 '20 at 04:32
  • I have moved plugin directive to module's pom but now it is trying to download it from public repository and giving following error. "Could not resolve dependencies for project com.myproject:.myproject:.cms:bundle:0.0.2-SNAPSHOT: Failure to find com.brightedge:be-ixf-java-sdk-jar-with-dependencies:jar:0.0.1-SNAPSHOT in https://repo.adobe.com/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of day-external-central has elapsed or updates are forced" – touseefkhan4pk May 25 '20 at 05:09
  • @touseefkhan4pk Could you add the updated pom.xml in your question itself. – Ananthapadmanabhan May 25 '20 at 05:35
  • I was supposed to edit my question but edited your answer mistaknly. – touseefkhan4pk May 25 '20 at 06:18