In versions of Maven before 2.1, there is no means to configure the client to timeout, but you can configure it to check for updates less often if you set the update policy. This partially addresses the problem.
For example:
<repository>
<id>myrepo</id>
<url>http://maven.mycompany.com/m2</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
Valid values are:
- always - always check when Maven is started for newer versions of snapshots
- never - never check for newer remote versions. Once off manual updates can be performed.
- daily (default) - check on the first run of the day (local time)
- interval:XXX - check every XXX minutes
Another consideration is the software you are using to host your internal repository. With a repository manager such as Nexus you can manage all your external remote repository connections through the manager and configure the timeout for those remote connections. Your client will then only query the repository manager, which should respond as quickly
as the timeouts allow.
Update:
If you know the dependencies aren't going to be served by a particular repository, you can separate it into a profile, so it is not referenced in that build.
<profiles>
<profile>
<id>remote</id>
<repositories>
<repository>
<id>central</id>
<url>http://repo1.maven.org</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
...
</repositories>
</profile>
<profile>
<id>internal</id>
<repositories>
<repository>
<id>myrepo</id>
<url>http://maven.mycompany.com/m2</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
...
</repositories>
</profile>
</profiles>
With the above config, running mvn package -Premote will not connect to the internal repository, so the timeout won't be a factor.
You can avoid having to specify the profiles on each build by adding some extra config to your settings:
<settings>
...
<activeProfiles>
<activeProfile>internal</activeProfile>
<activeProfile>remote</activeProfile>
</activeProfiles>
...
</settings>
For Maven 2.1 you can set the timeout by adding a configuration on a server in the Maven settings, for example:
<server>
<id>myrepo</id>
<configuration>
<timeout>5000</timeout> <!-- 5 seconds -->
</configuration>
</server>