0

I have a dependency and a dependent component in my Maven project.

I have successfully created the jar of the dependency project, using clean install -

[INFO] Installing /Users/sandeepan.nath/Desktop/codebase/path/to/component1/target/project-component-1-1.0.1-SNAPSHOT.jar to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/project-component-1-1.0.1-SNAPSHOT.jar
[DEBUG] Writing tracking file /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/_remote.repositories
[INFO] Installing /Users/sandeepan.nath/Desktop/codebase/path/to/project-component-1/pom.xml to /Users/sandeepan.nath/.m2/repository/com/path/to/project-component-1/1.0.1-SNAPSHOT/project-component-1-1.0.1-SNAPSHOT.pom
[DEBUG] Writing tracking file /Users/sandeepan.nath/.m2/repository/path/to-project-component-1/1.0.1-SNAPSHOT/_remote.repositories
[DEBUG] Installing com.project:project-component-1:1.0.1-SNAPSHOT/maven-metadata.xml to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/maven-metadata-local.xml
[DEBUG] Installing com.project:project-component-1/maven-metadata.xml to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/maven-metadata-local.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------

I also confirmed that the repository is present in the path - /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/

Following is the permission of the files generated -

SandeepanNath:1.0.1-SNAPSHOT sandeepan.nath$ ls -l
total 312
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users     264 Jul 26 21:24 _remote.repositories
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users  107794 Jul 26 21:24 project-component-1-1.0.1-SNAPSHOT.jar
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users     428 Jul 26 19:19 project-component-1-1.0.1-SNAPSHOT.jar.lastUpdated
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users    6733 Jul 26 21:01 project-component-1-1.0.1-SNAPSHOT.pom
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users     428 Jul 26 19:19 project-component-1-1.0.1-SNAPSHOT.pom.lastUpdated
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users     739 Jul 26 21:24 maven-metadata-local.xml
-rw-r--r--  1 sandeepan.nath  IDC\Domain Users     342 Jul 26 21:26 resolver-status.properties

Note - I am not sure why the jar is not present in the target directory of the component. As per my understanding, the jar of the dependency component will be first lookup in the target directory of the project, then in the maven local repository, and finally in the remote repository.

Now, when I am trying to run clean install on the dependent component, I am getting the following error -

Is dependent project trying to reference to .m2 or /target folder of dependency project?

[ERROR] Failed to execute goal on project project-component-2: Could not resolve dependencies for project project-component-2:jar:1.0.1-SNAPSHOT: Failed to collect dependencies at project-component-1:jar:1.0.1-SNAPSHOT: Failed to read artifact descriptor for project-component-1:jar:1.0.1-SNAPSHOT: Could not find artifact project:path:pom:1.0.1-SNAPSHOT in nexus (https://project-repository.com/repository/maven-public/) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project project-component-2: Could not resolve dependencies for project project-component-2:jar:1.0.1-SNAPSHOT: Failed to collect dependencies at project-component-1:jar:1.0.1-SNAPSHOT
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:269)

This repository url is defined in maven settings.xml as -

<localRepository>/Users/sandeepan.nath/.m2/repository</localRepository>
<servers>

    <server>
        <id>repo-id</id>
        <username>cred</username>
        <password>cred</password>
    </server>
    <server>
        <id>repo-id-2</id>
        <username>cred</username>
        <password>cred</password>
    </server>
    <server>
        <id>repo-id-3</id>
        <username>cred</username>
        <password>cred</password>
    </server>
<server>
        <id>repo-id-4</id>
        <username>cred</username>
        <password>cred</password>
    </server>
    <server>
        <id>repo-id-5</id>
        <username>cred</username>
        <password>cred</password>
    </server>
</servers>


<mirrors>
       <mirror>
      <id>repo</id>
      <mirrorOf>repo-id-5</mirrorOf>
      <url>https://project-repository.com/repository/maven-snapshots</url>
    </mirror>
    <mirror>
      <id>repo-id-4</id>
      <mirrorOf>nexus-snapshots-prepaid</mirrorOf>
      <url>https://project-repository.com/repository/maven-snapshots</url>
    </mirror>
    <mirror>
      <id>repo-id-1</id>
      <mirrorOf>*</mirrorOf>
      <url>https://project-repository.com/repository/maven-public/</url>
    </mirror>
</mirrors>

Note - Please ignore, if I have done any mistakes during replacing the actual names/paths of the project.

Update

Maven version 3.3.9. Java version 1.8.

Update 2

Here is some section (may be relevant) from the pom of the dependency component -

<parent>
        <groupId>com.project</groupId>
        <artifactId>project-base</artifactId>
        <version>1.0.1-SNAPSHOT</version>
        <relativePath>../../</relativePath>
    </parent>

    <artifactId>project-component-1</artifactId>
    <packaging>jar</packaging>

    <name>project-component-1</name>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.project.dependencies</groupId>
                <artifactId>dependency-of-project-component-1</artifactId>
                <version>1.0-SNAPSHOT</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

Update 3

I tried earlier with the Update Snapshots configuration -

enter image description here

I also tried with mvn clean install -U but same results.

Update 4

As per this comment -

I guess you have a problem in your local repository. Delete the directory /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/ and then build the first artifact again.

Tried that as well but still same error. On deleting the 1.0.1-SNAPSHOT directory, and building the first artifact, that directory appeared again, with only the .jar file. I guess, earlier the .lastUpdated file was also there. However, error on trying to build the 2nd artifact remains same.

Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144

1 Answers1

1

You need to call clean install with -U because there are lastUpdated files in your local repository. These cache that the artifact is not existent.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • I was already doing `clean install` with Update Snapshots checked. Not sure if that was doing the needed thing. Anyway, I tried with -U as well, but still getting the same error. – Sandeepan Nath Jul 27 '19 at 08:33
  • Is `-U` supposed to try to download from remote repository? I am not sure if these project component jars will be present in the remote repository. I am expecting these to be created in my project target folder, but these are getting creating in local repository. – Sandeepan Nath Jul 27 '19 at 08:36
  • Then I guess you have a problem in your local repository. Delete the directory `/Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/` and then build the first artifact again. – J Fabian Meier Jul 27 '19 at 08:38
  • Tried that as well but still same error. On deleting the 1.0.1-SNAPSHOT directory, and building the first artifact, that directory appeared again, with only the .jar file. I guess, earlier the .lastUpdated file was also there. However, error on trying to build the 2nd artifact remains same. – Sandeepan Nath Jul 27 '19 at 08:55
  • After trying to build the second artifact, did you get the same lastupdated files again? – J Fabian Meier Jul 27 '19 at 10:08
  • No, for the second artifact, the jars are not yet creating, as the build is failing. However, I see target directories now created against the first as well as the second ones. So, I guess, clearing the lastUpdated ones worked. – Sandeepan Nath Jul 27 '19 at 13:02
  • Just one remark: Maven never resolves again the target directory of another project. – J Fabian Meier Jul 27 '19 at 13:25