Maven - using a local source instead of an external dependency

If someone can help me here, it will save me a lot of time.

I maintain an open source library that pops into the sonata repository. I make changes to this library several times a day and push it into the 1.0_snapshot assembly using mvn deploy. Let me call him project1

I am constantly working on another project that uses this library to call it project2.

Right now, whenever I make changes to project 1 or 2, I need to first create and deploy project 1 in the repo, and then build project 2 so that it downloads a new copy of project1.jar

Project2 has Project1 as a dependency in pom.xml:

<dependency> <groupId>com.group</groupId> <artifactId>project1</artifactId> <version>1.0-SNAPSHOT</version> </dependency> 

to build in such a way that all my changes can be tested, I have to do something like this:

 mvn -f ./project1/pom.xml clean deploy mvn -U -f ./project2/pom.xml clean package 

this loads my project1.jar into sonatype, then project2 loads a new snapshot and builds it.

This is a simplified picture of what I am doing on a larger scale, where my compilers take 5 minutes and load.

Question: What is the correct way to use maven, so it knows how to use the project1 source depending on project 2?

+6
source share
2 answers

IDE:

  • install m2e in eclipse
  • import both projects into the workspace
  • from user project (right click> maven> allow workspace permission)

this will put the project2 classes in the classpath from its target / classes instead of the actual jar

native direct maven:

  • You can create a maven project tree , if these two open source projects go through the same build cycle, it should have it already, if they are not connected but connected for your usecase, then you can temporarily create a maven tree on top of these two projects and build the upper parent, which he will build from the bottom up in one team.

he will find the sheet project, create it, install it in the maven cache and now, building projectA, he will refer to it from the maven cache, so there is no need to deploy it in sonatype

+6
source

You can also tell project2 to build offline:

 mvn -o package 

Then you remove the downloadable part of the project1 assembly to the remote repo.

Check out the following link: Intro to the repository and How to configure Maven for offline development?

+3
source

Source: https://habr.com/ru/post/980441/


All Articles