0

I have 3 projects in the same directory. Project 1 can run on its own. Project 2 requires project 1. Project 3 requires project 2 and project 1.

I do not wish to upload the projects to a remote depository. So

Project 1 should build as normal. It should not know about other users of it or contain information about their builds.

Project 2 would require building/importing Project 1.

Project 3 would require building/importing Project 1 and 2 - or - Project 2 plus recursive dependencies.

The project 2 pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.project2</groupId>
<artifactId>project2</artifactId>
<version>1</version>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>com.project1</groupId>
        <artifactId>project1</artifactId>
        <version>1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.5.1</version>
            <configuration>
                <groupId>com.project1</groupId>
                <artifactId>project1</artifactId>
                <version>1</version>
                <packaging>jar</packaging>
                <file>${project.basedir}/../project1/target/project1-1.jar</file>
                <pomFile>${project.basedir}/../project1/pom.xml</pomFile>
            </configuration>
            <executions>
                <execution>
                    <id>install-project1-jar</id>
                    <goals>
                        <goal>install-file</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

That works.

The project 3 pom.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.project3</groupId>
<artifactId>project3</artifactId>
<version>1</version>
<packaging>jar</packaging>

<dependencies>
    <dependency>
        <groupId>com.project2</groupId>
        <artifactId>project2</artifactId>
        <version>1</version>
    </dependency>
</dependencies>

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
            <groupId>com.project2</groupId>
            <artifactId>project2</artifactId>
            <version>1</version>
            <packaging>jar</packaging>
             <file>${project.basedir}/../project2/target/project2-1.jar</file>
            <pomFile>${project.basedir}/../project2/pom.xml</pomFile>
        </configuration>
        <executions>
            <execution>
                <id>install-project2-jar</id>
                <goals>
                    <goal>install-file</goal>
                </goals>
                <phase>validate</phase>
            </execution>
        </executions>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
        </configuration>
    </plugin>
</plugins>
</build>

That only retrieves dependencies for Project 2, the build does not find/retrieve dependencies for Project 1. It cannot find the pom.

How can I make maven find local dependencies more than one level up in the hierarchy of dependencies for the install-file plugin or for a different/better method?

nsandersen
  • 896
  • 2
  • 16
  • 41

1 Answers1

0

I would suggest that you change this to be a multi module project. Your setup seems very complex.

Jim Sellers
  • 523
  • 3
  • 15
  • 3 levels seem simple compared to some of the dependence trees maven resolves from repositories? Anyway, let me know what you mean by multi module setup? (It is already modularized in projects in a sense.) – nsandersen Nov 09 '19 at 14:22
  • If the project is all in the same source project ( e.g. git repo), then you can have a parent pom and 3 modules. If the project is a "whole package" and they will all be released together, then I'd structure it this way. Maven will figure out the dependencies this way. parent +- project 1 +- project 2 \- project 3 https://www.baeldung.com/maven-multi-module This is very useful since you can set things like compiler config, dependency management, source control info, etc in the top level pom and the children inherit it. Some projects I work on have 1 pom / module, some have 40. – Jim Sellers Nov 14 '19 at 20:35