1

I have a project A which depends on artifact B. I made some hack on B, and want to see it in A. So I don't want A to use the version in my local repository, instead, I want A to use my hacked version of B.

I'm looking for a solution that can specify my-hacked-B.jar as dependency of A, like this:

cd A && mvn package -Ddependency.org.groupB.B.jar.path=path/to/my-hacked-B.jar

Is it possible, or I have to install the modified B in my local repository?

Yang Bo
  • 3,586
  • 3
  • 22
  • 35
  • You can do this from command line: http://stackoverflow.com/questions/1776496/a-simple-command-line-to-download-a-remote-maven2-artifact-to-the-local-reposito – cwu9T9 Dec 05 '12 at 20:40

4 Answers4

2

You can't do it on the command line, but you can set the dependency scope to system in the pom.xml and provide a path to the dependency.

<dependency>
  <groupId>org.groupB</groupId>
  <artifactId>B</artifactId>
  <version>2.0</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/path/to/hacked-B.jar</systemPath>
</dependency>
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
1

A little bit late :) You can do it with properties:

<properties>
    <org.groupB.B.scope>compile</org.groupB.B.scope>
    <org.groupB.B.path></org.groupB.B.path>
</properties>

<dependency>
    <groupId>org.groupB</groupId>
    <artifactId>B</artifactId>
    <version>2.0</version>
    <scope>${org.groupB.B.scope}</scope>
    <systemPath>${org.groupB.B.path}</systemPath>
</dependency>

and then:

mvn package -Dorg.groupB.B.scope=system -Dorg.groupB.B.path=path/to/my-hacked-B.jar
Anton Bessonov
  • 9,208
  • 3
  • 35
  • 38
1

There is no way to resolve dependency from command line, but there is a way to let maven resolve dependency externally.

I created a temporal wrapper pom.xml which aggregates the two projects. It works, without install anything into local repository.

The only problem is that I am unable to use absolute path in <module/>.

See http://maven.apache.org/pom.html#Aggregation

Yang Bo
  • 3,586
  • 3
  • 22
  • 35
0

You could mvn clean install your hacked version into your local maven repo, over the version you downloaded from the 'net. You'd need to make sure that project B's pom reflects the version you are depending on and not a snapshot version. (Or, to put it more generally: The version of project B that you mvn clean install must match the version you require in project A. Whether you edit A's pom or B's pom doesn't matter.)

Matthew Read
  • 1,365
  • 1
  • 30
  • 50
davetron5000
  • 24,123
  • 11
  • 70
  • 98