【问题标题】:Not Publishing the mentioned file(war/tar/zip) to artifactory in gradle script不将提到的文件(war/tar/zip)发布到 gradle 脚本中的工件
【发布时间】:2015-04-16 22:47:32
【问题描述】:

我编写了一个 gradle 脚本,在其中创建 zip 和 war 文件,然后我需要将其上传/发布到工件,但问题是我在工件任务中指定了 war 文件,即使之后它正在将所有内容发布到Artifactory zip、tar 和 war 而不仅仅是 war 文件。

apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'distribution'

//-- set the group for publishing
group = 'com.xxx.discovery'

/**
 * Initializing GAVC settings
 */
def buildProperties = new Properties()
file("version.properties").withInputStream { 
    stream -> buildProperties.load(stream) 
} 
//add the jenkins build version to the version
def env = System.getenv()
if (env["BUILD_NUMBER"]) buildProperties.coveryadBuildVersion += "_${env["BUILD_NUMBER"]}"
version = buildProperties.coveryadBuildVersion
println "${version}"

//name is set in the settings.gradle file
group = "com.aaa.covery"
version = buildProperties.discoveryadBuildVersion
println "Building ${project.group}:${project.name}:${project.version}"

  repositories {
    maven {
      url "http://cxxxxt.tshaaaaa.tho.com:9000/artifactory/libselease"
    }
    maven {
      url "http://cxxxxt.tshaaa.tho.com:9000/artifactory/cache"
    }
  }

dependencies {
    compile ([
    "com.uters.omni:HermesSessionAPI:1.2",
    "com.uters.proxy:ProxyResources:1.1",
    "com.uters.omni:SeshataDirectory:1.0.1" ,
    "com.euters.omni:CybeleInfrastructure:1.1.2",
    "com.euters:JSONBus:1.4.1",
    "javaee:javaee-api:5"
    ])
}

distributions {
  main { 
    contents { 
      from {
        war.outputs
        }
      }
  }
}

// for publishing to artifactory
artifacts {
  archives war
}

【问题讨论】:

  • 这是你的完整剧本吗?似乎缺少某些部分(例如,publishArchives 配置、ZIP/TAR 创建等)。
  • 是的,这是我的完整脚本,基本上是 distrubiton 插件创建了 zip 和 tar 文件。我正在使用基本上创建 war 文件的 war 文件

标签: gradle build.gradle artifactory gradle-plugin


【解决方案1】:

根据gradle distribution plugin documentation

“src/$distribution.name/dist”目录中的所有文件都将自动包含在分发中。

还有,

分发插件将分发档案添加为默认发布工件的候选者。

换句话说,默认情况下所有文件都将被发布,因此这解释了您遇到的行为。

为了解决此问题,您可以做的可能是通过明确排除不需要的文件来更准确地定义 contents copySpec,即:

distributions {
  main { 
    contents { 
      exclude('**/.zip')
      exclude('**/.tar')
      from {
        war.outputs
      }
    }
  }
}

请注意,我并没有自己尝试上述方法,因此可能需要进行一些微调。不过我相信你可以在CopySpec Interface documentation中找到你需要的数据

【讨论】:

  • 感谢您的回复。我正在将我的 gradle 脚本与 Jenkins 一起使用,所以我正在使用 gradle artifactory 插件,我可以在其中放置我想要排除/包含的参数,并且我能够成功地做到这一点。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-11
  • 2022-12-10
  • 1970-01-01
  • 2020-05-13
  • 1970-01-01
  • 1970-01-01
  • 2016-03-24
相关资源
最近更新 更多