【问题标题】:How to specify the maven local repository path with artifactory plugin?如何使用 artifactory 插件指定 maven 本地存储库路径?
【发布时间】:2017-12-20 03:52:53
【问题描述】:

我在 Jenkinsfile 中使用 artifactory 插件来驱动我的 maven 构建:

def goals = "clean install"
def artifactory = Artifactory.server 'artifactory'

configFileProvider([configFile(fileId: 'simple-maven-settings', variable: 'MAVEN_USER_SETTINGS')]) {
    def mavenRuntime = Artifactory.newMavenBuild()
    mavenRuntime.tool = 'maven350'
    mavenRuntime.resolver server: artifactory, releaseRepo: '…', snapshotRepo: '…'
    mavenRuntime.deployer server: artifactory, releaseRepo: '…', snapshotRepo: '…'

    def buildInfo = mavenRuntime.run pom: 'pom.xml', goals: "-B -s ${MAVEN_USER_SETTINGS} ${goals}".toString()

这很好用,但是 maven 使用默认的共享位置 ~/.m2/repository

我想重现我在迁移到管道之前的行为并为每个作业提供自己的本地存储库。

我没有找到任何设置... 我应该如何进行?

【问题讨论】:

    标签: maven jenkins-pipeline artifactory


    【解决方案1】:

    默认情况下,maven 使用用户 home 下 .m2 目录中的本地 maven 存储库。 如果您希望 maven 创建本地存储库,例如,在您的工作工作区中,请将 -Dmaven.repo.local=.m2 系统属性添加到目标值,如下所示:

    def buildInfo = rtMaven.run pom: 'pom.xml', goals: 'clean install -Dmaven.repo.local=.m2'
    

    -Dmaven.repo.local 的值指向用于此 maven 构建的本地 maven 存储库。 你可以阅读更多关于它here`

    【讨论】:

      【解决方案2】:

      您可以在Jenkins Pipeline with Maven 中这样做:

        withMaven(
              // Maven installation declared in the Jenkins "Global Tool Configuration"
              maven: 'M3',
              // Maven settings.xml file defined with the Jenkins Config File Provider Plugin
              // Maven settings and global settings can also be defined in Jenkins Global Tools Configuration
              mavenSettingsConfig: 'my-maven-settings',
              mavenLocalRepo: '.repository') {
      
            // Run the maven build
            sh "mvn clean install"
      
          } // withMaven
      

      您可以在此处简单地定义本地缓存位置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-21
        • 2012-11-09
        • 2014-12-22
        • 1970-01-01
        • 2012-05-08
        • 2012-04-30
        • 1970-01-01
        • 2021-07-11
        相关资源
        最近更新 更多