Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven - using local source instead of external dependency

If someone could help me out here it would save me a lot of time.

I maintain an open source library that gets pushed out to a sonatype repository. I make changes to that library a few times a day and push it out to the 1.0_snapshot build using mvn deploy. Let's call it project1

I work constantly in another project that uses that library let's call it project2.

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

Project2 has Project1 as a dependency in a pom.xml:

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

 </dependency>

in order to build in a way where all of 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 uploads my project1.jar to sonatype, then project2 downloads the new snapshot and builds it.

This is a simplified picture of what i'm doing on a larger scale, where my compiles take 5 minutes of up and downloads.

Question: What is the proper way to use maven so it knows to use the source of project1 in a dependency in project 2?

like image 503
bsautner Avatar asked Jan 02 '15 20:01

bsautner


1 Answers

IDE:

  • install m2e in eclipse
  • import your both projects into workspace
  • from consumer project (right click > maven > enable workspace resolution)

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

native straight maven:

  • You can create a maven project tree, if this two are open source project going through same build cycle it must have one already, if they are not related but related for your usecase then you can temporarily create a maven tree on top of these 2 projects and build the top parent it will build from bottom up in one command

it will find the leaf project, build it install it in maven's cache and now while building projectA it will refer it from maven's cache so no need to deploy to sonatype

like image 168
jmj Avatar answered Sep 23 '22 06:09

jmj