2

I have created a maven dependency in Github package. I am trying to install this dependency in my another mule project.

settings.xml:

<server>
    <id>github</id>
    <username><owner></username>
    <password><Token></password>
</server>

<profile>
      <id>github</id>
      <repositories>
        <repository>
          <id>central</id>
          <url>https://repo1.maven.org/maven2</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>github</id>
          <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
          <releases>
            <enabled>true</enabled>
          </releases>
        </repository>
      </repositories>
    </profile>
  </profiles>

Dependency from Github package:

<dependency>
  <groupId>com.mycompany</groupId>
  <artifactId>hello-world-3</artifactId>
  <version>1.0.11-SNAPSHOT</version>
</dependency>

I have created a hello world mule application and added the dependency in Pom.xml and ran mvn install on command prompt.

Getting this error:

D:\WorkSpace\test-package-dependency>mvn install
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.mycompany:test-package-dependency >----------------
[INFO] Building test-package-dependency 1.0.0-SNAPSHOT
[INFO] --------------------------[ mule-application ]--------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.845 s
[INFO] Finished at: 2021-11-19T17:21:57+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project test-package-dependency: Could not resolve dependencies for project com.mycompany:test-package-dependency:mule-application:1.0.0-SNAPSHOT: Failure to find com.mycompany:hello-world-3:jar:1.0.11-SNAPSHOT in https://maven.anypoint.mulesoft.com/api/v2/maven was cached in the local repository, resolution will not be reattempted until the update interval of anypoint-exchange-v2 has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

I have searched online and did not get solution for my error. Also, tried jitpack. It didnt help too.

anonymous
  • 81
  • 9

1 Answers1

0

you have to define access repository url in pom.xml of your project where you wanted to access.

Just define like below,

<repositories>
    <repository>
      <id>central</id>
      <url>https://repo1.maven.org/maven2</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
    <repository>
      <id>github</id>
      <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>true</enabled>
      </releases>
    </repository>
  </repositories>

or also try only with id and url

<repositories>
    <repository>
      <id>central</id>
      <url>https://repo1.maven.org/maven2</url>
    </repository>
    <repository>
      <id>github</id>
      <url>https://maven.pkg.github.com/<owner>/<repo-name></url>
    </repository>
  </repositories>

Notes: Make sure you have given access to read or download the jar so that Maven can easily download for you while running maven phases.

Manish Yadav
  • 210
  • 5
  • 8
  • Thanks for your response @Manish. It is working!! – anonymous Nov 30 '21 at 04:02
  • You don't need to attach the `` element for https://repo1.maven.org/maven2 because Maven documentation says "You will also get the standard set of repositories as defined in the Super POM." See: https://maven.apache.org/guides/mini/guide-multiple-repositories.html – Krzysztof Tomaszewski May 13 '23 at 16:13