0

I have a project structure like below:

- app
  - app-repo
  - app-service
  - app-controller
  - lib (custom jar placed here)
  - pom.xml (parent pom)

My parent pom include the submodules and a repository location to get jar from lib folder

    <repositories>
        <repository>
            <id>in-project</id>
            <name>In Project Repo</name>
            <url>file://${main.basedir}/lib</url>
        </repository>
    </repositories>
    
    <modules>
        <module>app-repo</module>
        <module>app-service</module>
        <module>app-controller</module>
    </modules>

    <properties>
        <main.basedir>${project.basedir}</main.basedir>
        <jar.version>1.7</jar.version>
        <release.version>1.0-SNAPSHOT</release.version>
    </properties>

    <dependencies>
        <dependency>  <!-- jar file located in lib folder -->
            <groupId>com.custom</groupId>
            <artifactId>custom-core</artifactId>
            <version>${jar.version}</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

My maven build order:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] app                                                [pom]
[INFO] app-repo                                           [jar]
[INFO] app-service                                        [jar]
[INFO] app-controller                                     [jar]

and it failed with error when building app-repo:

Failure to find com.custom:custom-core:jar:1.7 in
file://C:\Windows\System32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\My_APP\app-repo/lib was cached in the local repository

What I found is maven inherits the <repositories> from parent pom during the submodules build, so <url>file://${main.basedir}/lib</url> is causing maven to look for app-repo/lib and hit the error.

So I would like to know what is the best practice to handle this scenario?

  1. How to make sure maven will always get the jar from the lib folder and ignore for the submodules ?
  2. What is the correct/best configuration for the parent pom.xml ?

I tried to add <url>file://${project.parent.basedir}/lib</url> into the child pom.xml in app-repo like below:

    <repositories>
        <repository>
            <id>in-project</id>
            <name>In Project Repo</name>
            <url>file://${project.parent.basedir}/lib</url>
        </repository>
    </repositories>

or

    <properties>
        <main.basedir>${project.parent.basedir}</main.basedir>
    </properties>

but both also seem like not able to refer to parent folder and hit below error

Failure to find com.custom:custom-core:jar:1.7 in
file://${project.parent.basedir}/lib was cached in the local repository
Tony_Ynot
  • 155
  • 1
  • 14

1 Answers1

0

After getting hints from J Woodchuck, I'm able to find a answer from here

Since 3.0.4, ${parent.basedir} is not longer available, so pom.xml in child need to be like this to make it able to refer to parent project directory:

<main.basedir>${project.basedir}${file.separator}..</main.basedir>
Tony_Ynot
  • 155
  • 1
  • 14