0

That's it. I want to know how I can construct pom.xml and setting.xml so that my build will check two repo's. The server repo, and a local repo? How can I do this. Please be clear and descriptive. Not oh you have to add LocalRepo to setting.xml. Did that. It does not tell to use multi. Putting it in pom, it just ignores the local repo and goes to server only error if its not on the server. I know this is beginner question, so just answer it please. Not some little snippets of information like put in settings not in pom? Why not in pom? And how exactly in settings? Its not enough just to add localRepo? Does it need to be under profile? etc.

In my settings.xml :

  <mirrorOf>*</mirrorOf>
        <url>http://myserver:8080/nexus/content/groups/public</url>
    </mirror>
</mirrors>

As long as this mirror is there, it seems to check only this repo url, and if it does not find what its looking for it provides error to wait until next update. it never checks local repo. How can I keep this mirror but also have it check additional repo's?

MuayThai
  • 441
  • 1
  • 5
  • 19
  • What do you mean by local repo? Using repository manager ? – khmarbaise Oct 26 '15 at 11:56
  • I mean there are some jars, aar archives in a local sdk path on my local machine. Basically I have android sdk installed and it provides local repo of jars and libraries that are part of google's android sdk. But there are other jars that I want to get from central repo as well. This is really just one library that I am trying to pull from local machine. That's it, and basically just wasted a day on this issue. – MuayThai Oct 26 '15 at 13:27

1 Answers1

1

I don't like rants about Maven so I'm going to be as descriptive as I can.

There are 2 ways to add new repositories to Maven, that is to say to tell Maven about where it should look for dependencies.

  • In the POM.
  • In the user or global settings.

POM

In the POM, you add a repository by declaring it inside the <build> <repositories> <repository> element.

<project>
...
  <repositories>
    <repository>
      <id>my-repo1</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
    <repository>
      <id>my-repo2</id>
      <name>your custom repo</name>
      <url>http://jarsm2.dyndns.dk</url>
    </repository>
  </repositories>
...
</project>

User / Global settings

This is done by modifying the ~/.m2/settings.xml file (for user settings) or $M2_HOME/conf/settings.xml (for global settings). In this case, repositories are added to a profile that is made active by default:

<settings>
 ...
 <profiles>
   ...
   <profile>
     <id>myprofile</id>
     <repositories>
       <repository>
         <id>my-repo2</id>
         <name>your custom repo</name>
         <url>http://jarsm2.dyndns.dk</url>
       </repository>
     </repositories>
   </profile>
   ...
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
 ...
</settings>

Hopefully, this is clear enough.

  • For a local repository, the URL is: file://path/to/repo
  • For a remote repository, the URL is: http[s]://path/to/repo

Now, it is considered a best practice to put this information in the settings instead of the POM because this information will typically be the same for every project you have. This is corporate information and we need to treat it globally, not per project. If you need it per project, then you can add it to your POM. The result will be the same.

Repositories can be further configured by specifying the release or snapshot mode, update policy, etc. Please refer to the documentation about this.


Mirror

In your edit, you are using a mirror. To configure a mirror to only be used for a specific repository, you can have the following configuration in the settings:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <mirror>
      <id>my-wonderful-mirror</id>
      <url>http://myserver:8080/nexus/content/groups/public</url>
      <mirrorOf>id-of-your-repository</mirrorOf> <!-- this is the ID of the repository, i.e. what is inside settings > profiles > profile > repositories > repository > id -->
    </mirror>
  </mirrors>
  ...
</settings>

This way, you can configure a mirror for the remote repository and not for the local one.

Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • ok, i will try. let me see if I put both repo's local and remote in pom if it will check both. That's what I need. – MuayThai Oct 26 '15 at 12:49
  • well I have a mirror, and as long a that mirror is in my settings.xml file it goes there and only there. Only if I remove the mirror which points to server repo does it check local repo. But that means I am checking only local repo and not both. – MuayThai Oct 26 '15 at 13:24
  • @MuayThai You didn't mention a mirror in your initial question. See my edit. – Tunaki Oct 26 '15 at 13:29
  • well I did not think there is anything about mirrors that give them priority over a local repo. Does repositories really go under ? I don't think that works. It seems it needs to be level up. When I put repos directly under build I get an error. repositories not recognized – MuayThai Oct 26 '15 at 13:30
  • So the question is how can I have the mirror, and also have it check a local repository as well? Do I need a mirror for my local as well? It seems if there is a mirror in use it needs to include every repo you want visible. So mirrors must have entry for each repo? – MuayThai Oct 26 '15 at 13:33
  • @MuayThai Did you read my edit? You can configure a mirror _per repository_ so you only need to configure it for the remote repository and NOT the local one. – Tunaki Oct 26 '15 at 13:38
  • well that's what I've got, but as long as its there, it checks only the mirror and not the local repo. It just stops and provides an error if it does not find it in the mirror. If I remove the mirror entry than it checks the local repo I declared in the pom ...So it's a one or the other situation right now, but I need it to check both. – MuayThai Oct 26 '15 at 13:39
  • @MuayThai Then obviously you have misconfigured something. Read carefully my _whole_ answer. `` element MUST contain the ID of the remote repository (as I said in my answer). You could also use [`external:*`](https://maven.apache.org/guides/mini/guide-mirror-settings.html) which tells Maven to use the mirror for everything not on the localhost and not file based. – Tunaki Oct 26 '15 at 13:43
  • Ok thanks, I did not realize scope of mirrors when they have the * settings and the precedence over local or other repos with this settings. – MuayThai Oct 26 '15 at 14:00