0

I would like to get the URL of the maven repository being used by the project in the pom.xml.

I tried the suggestion as described at Maven: Get repository URL of a dependency but wasn't successful at getting the URL. On further exploration I found ${project.pluginRepositories} listing the list of the repository. However, I wasn't able to extract the URL from the pluginRepositories list.

echo of ${project.pluginRepositories} prints [id = 'maven-releases', id = 'central']. 

I'm looking for a way to extract "central" repository URL.

Jens
  • 67,715
  • 15
  • 98
  • 113
Chandan C
  • 138
  • 1
  • 11
  • 1
    Why not use the standard maven central url? – J Fabian Meier Mar 26 '19 at 18:49
  • We have local mirrors & some internal artifacts, hence I wanted to use config as defined in the settings.xml – Chandan C Mar 27 '19 at 04:58
  • Ok, you confuse me. Above you are talking about repositories from a POM, then you talk about pluginRepositories, now you speak about config from the settings.xml. What exactly do you want to find out? Maybe it is easier if you explain some background because maybe there is already a solution for your original problem that is less complicated. – J Fabian Meier Mar 27 '19 at 07:36
  • Maybe I'm not able to clearly convey my use case. I want to have a utility to download & configure some files (part of internal maven/artifactory/external URL). So I want to pass the repo URL when that utility is integrated to maven, since I don't want to be always editable, I want to read from the available configuration & pass to utility. Hence I was trying to access project.pluginRepositories in pom. – Chandan C Mar 29 '19 at 05:58

1 Answers1

0

I have following thoughts in this context:

1) Just run command mvn --version. Go to maven installation directory and view the content of settings.xml file under conf folder. It should tell you which maven central repository is being used. It could be possible that there is no specific repository listed there. If that is the case then either default central repository is being used or it will be determined from content of pom.xml file of maven module.

2) If settings.xml file does not have any specific repository mentioned then go to maven module and check effective-pom. It should tell you which maven central repository is being used. You might get similar to following tags in your effective-pom file

<repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
    </repository>
  </repositories>

Following links should also help you further:

http://maven.apache.org/ref/3.6.0/maven-model-builder/#Model_Interpolation http://maven.apache.org/ref/3.6.0/maven-settings/settings.html

Please try using ${settings.repositories} which will return List<Repository>

Anshul Singhal
  • 1,983
  • 20
  • 25
  • Do you know how can I loop through the list of values from ${settings.repositories} to get each repo URL. Within pom.xml – Chandan C Mar 30 '19 at 14:15