Rockoder
Rockoder

Reputation: 784

maven to use local jar in repository and not go to remote repo

Setup:

Project A
Project B
Project A use Project B as dependency

via parent's mechanism (they both go to top level parent which has all dependencies defined in it). They have their own parent hierarchy too. I would like to use locally built Project B and force maven to use that rather than pulling from Remote repo (we use nexus). I have tried -o option but it does not work. What's the best way for maven to stop looking for remote dependency and use locally built dependency to test local changes before committing.

EDIT - adding XMLs for reference

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 ...">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.rockoder.myproject</groupId>
  <artifactId>myproject-parent</artifactId>
  <version>1.0.1-main-iteration-01-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>myproject Top Parent</name>
  <description>This is the root of all projects. Versions and metadata are being specified here</description>
  <scm... </scm>
  <distributionManagement>...</distributionManagement>
  <properties>...</properties>
  <dependencyManagement>
    <dependencies>
     ....  
      <dependency>
        <groupId>com.rockoder.myproject</groupId>
        <artifactId>Project B</artifactId>
        <version>1.0.1-01-SNAPSHOT</version>
        <type>pom</type>
      </dependency>    
      <dependency>
        <groupId>com.rockoder.myproject</groupId>
        <artifactId>Project A</artifactId>
        <version>1.0.1-01-SNAPSHOT</version>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <repositories>...</repositories>
  <pluginRepositories> .... </pluginRepositories>
  <build>....</build>
  <profiles>...</profiles>
</project>

Upvotes: 1

Views: 4652

Answers (1)

dur
dur

Reputation: 16969

As @Tunaki commented: you have to install your parent POM, to be sure, that all modules are built, see Maven by Example - Chapter 6. A Multi-Module Project:

With the simple-weather project containing all WAR file. To do this, you will want to compile and install both projects in the appropriate order; since simple-webapp depends on simple-weather, the simple-weather JAR needs to be created before the simple-webapp project can compile. To do this, you will run mvn clean install command from the simple-parent project:

If you don't install your parent POM, you have to install first your Project B POM and then your Project A POM.

Maven will only load dependencies from remote repository, if dependencies are not in your local repository or a newer SNAPSHOT version is present in remote repository, see Introduction to Repositories:

Downloading in Maven is triggered by a project declaring a dependency that is not present in the local repository (or for a SNAPSHOT, when the remote repository contains one that is newer). By default, Maven will download from the central repository.

Upvotes: 1

Related Questions