下载maven项目依赖项以便稍后脱机构建

cyn*_*axa 5 java maven

我已经使用maven一段时间以常见的方式开箱即用,所以我明白它是什么,但我是maven设置中的新手.

我需要组织这样的工作流程:

  1. 开发人员编写java代码,使用来自Internet的一些依赖项.
  2. 开发人员承诺他的工作.
  3. TeamCity可以自动构建他的工作.没有任何手工工作,没有互联网.

我知道如何做到这一点:

  1. 开发人员使用maven."common"目录充当某些Java项目的存储库.
  2. 工作完成后,开发人员将他的项目和公共目录提交到svn.
  3. TeamCity从svn更新项目和公共目录并运行"mvn package".任何需要来自公共目录.无需担心互联网连接和启动nexus,或其他回购服务.

我的问题是:如何在文件系统上使用简单目录作为某些项目的代理存储库?请告诉我如何实现这个想法或给我另一个想法来实现这样的工作流程.

我可以提交本地存储库,但有一些限制:

  1. 本地repo zip工件.如果我对它做了很少的改动 - 整个缓存文件必须上传到svn或从svn下载.这需要很长时间.
  2. 所有项目的本地仓库工件.我只希望某些项目使用此repo,因为开发人员不想检查更改并过滤未使用的依赖项.

我通过在repo url中编写"file:// testRespoDir"来测试本地目录以部署项目,但是我无法理解如何使这个目录代理项目的所有远程工件(项目必须不使用本地存储并且只使用公共目录.

cyn*_*axa 4

I found simple and perfect solution: POM include 2 repositories:

<repositories>
    <repository>
        <id>commonDep</id>
        <name>common dependency</name>
        <url>file://../common/repository</url>
    </repository>
    <!-- it used when collect dependencies before commit. If developer already download dependency, get it from local repo, save traffik and time -->
    <repository>
        <id>localPlugins</id>
        <name>local plugins</name>
        <url>file://${user.home}/.m2/repository</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>commonDep</id>
        <name>common dependency</name>
        <url>file://../common/repository</url>
    </pluginRepository>
    <!-- it used when collect dependencies before commit. If developer already download dependency, get it from local repo, save traffik and time -->       
    <pluginRepository>
        <id>localPlugins</id>
        <name>local plugins</name>
        <url>file://${user.home}/.m2/repository</url>
    </pluginRepository>
</pluginRepositories>
Run Code Online (Sandbox Code Playgroud)

when developer opens project, he use local, common and central repositories in such order. It saves his traffic. When he finished work, he call script:

mvn dependency:go-offline -Dmaven.repo.local=../common/repository
Run Code Online (Sandbox Code Playgroud)

all current dependencies of project copyed from his default local repository to common repository. Then developer commit common.

When we run build on teamcity, we checkout project and common and run it. There is no internet connection, but all dependencies exist in common repository.