Gradle - 从Artifactory下载单个groupID的所有版本jar:artifactID [英] Gradle - Download all version jars of a single groupID:artifactID from Artifactory

查看:287
本文介绍了Gradle - 从Artifactory下载单个groupID的所有版本jar:artifactID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Gradle构建一个项目(Java)。



Gradle 2.3,Java7 / 8。为了构建一个项目,我们定义了在编译,测试(testRuntime)和运行阶段期间我们需要的所有库,我们在依赖关系部分定义所有这些库,如:

 依赖关系{
编译'some_groupID:some_artifactID:some_version_x.yz@ext_if_any'

testRuntime'SomeOtherOrSame_groupID:some_other_or_same_artifactID:some_version_x.yz@ext_if_any'

运行时'SomeOtherOrSame_groupID:some_other_or_same_artifactID:some_version_x.yz@ext_if_any'

}

我们在依赖项部分有多个这样的条目,用于我们的应用程序/服务运行构建/测试/ IT测试等所需的所有库(在运行时)。



Gradle到目前为止很好,下载了Artifactory的所有工件。



在一个项目中,我需要获取所有版本的工件(所有可用的依赖项) s)),即我想要以下.jar(默认扩展名),并创建一个包含所有版本化的.jars的zip文件:



<$编译'my.company.com:cool_library:1.0.0'
编译'my.company.com:cool_library:1.0.1'
编译'我的。 company.com:cool_library:1.1.0'
compile'my.company.com:cool_library:1.2.0'

运行时'my.company.com:another_cool_library:1.0.0'
运行时'my.company.com:another_cool_library:1.2.0'
运行时'my.company.com:cool_library:1.0.1'

我知道如何在Gradle中创建一个.zip文件(很简单),但是Gradle没有得到/下载所有的.jar(对于上面列出的每个版本)从Artifactory或从给定的二进制资料库系统。



它只得到最新的cool_service-1.2.0.jar)。 Gradle做的很好,因为这样你就不会在同一个项目(cool_library)的类路径中有重复的类,并且由于它在依赖关系部分提到的不同版本。有人会说,为什么当cool_library版本1.2.0中有最新/最好的代码时,如果正在使用该库的项目需要OLDER版本它只是说我想要 my.company.com:cool_library:1.2.0 ,并完成它,或获得任何您要编译的单个版本。在我的情况下,DEV团队已经编写了应用程序代码,方法是在这里定义cool_library-1.0.0.jar,但cool_library-1.2.0.jar在其他地方。基本上,我需要开发人员在build.gradle文件中定义的所有内容。



如何创建一个custom_zip.zip文件,它将具有所有的cool_library-xyzjar



谢谢。

解决方案

使用这个很棒的工具,这是可能的。阅读全文(以不同的方式做事情)。



链接 Gradle下载任务 https://github.com/michel-kraemer/gradle-download-task



例如:在您的build.gradle中,您将拥有:

 插件{
idde.undercouch.downloadversion1.2
}

import de.undercouch.gradle.tasks.download.Download
apply plugin:' java'
应用插件:'de.undercouch.download'


repositories {
maven {
urlhttp:// yourartifatory:1020 /文件/虚拟回复
}
}

//我想下载my.company.com:CoolServices:1.0 jar或任何扩展文件
//然后我可以创建一个列表,并指定所需要的内容:
def deps = [
[我/ company / com,CoolServices,1.0,jar ,
[我/公司/ com,CoolService s,1.1,jar],
[my / company / com,CoolServices,1.2,jar]
]

任务downloadArts<< {
//根据列表迭代每个依赖项
deps.each {groupId,artifactId,version,extn - >
下载{
srchttp://yourartifactory.fqdn.com:1020/artifactory/simple/some-physical-actual-repository-local/$groupId/$artifactId/$version/$artifactId- $ version。$ extn
dest buildDir
//如果您希望在build / xxx文件夹中下载的文件,请先在clousure ie文件(build / xxx)之外创建该xxx文件夹。mkdir ()
}
}
}


现在,运行 gradle clean downloadArts ,它将打印要下载的内容,或者在 build build / xxx 文件夹,您可以在其中找到所有下载的文件(.dar文件,您在deps列表变量中提到的.jar / etc扩展文件)。



您还可以使用它来推送到依赖关系部分进行编译,运行时,testRuntime或者如果需要,可以创建一个custom_zip.zip文件。



例如:

 依赖项{
编译fileTree(dir:build,include: '*。*')
运行时文件Tree(dir:build / xxx,include:'*。*')
}

或创建一个custom_zip.zip文件(包含所有下载的.jar /扩展文件)。


I use Gradle to build a project (Java).

Gradle 2.3, Java7/8. Works great.

To build a project, we define what all libraries we need during compile, test (testRuntime) and runtime stages and we define all those libraries in dependencies section like:

dependencies {
    compile 'some_groupID:some_artifactID:some_version_x.y.z@ext_if_any'

    testRuntime 'SomeOtherOrSame_groupID:some_other_or_same_artifactID:some_version_x.y.z@ext_if_any'

    runtime 'SomeOtherOrSame_groupID:some_other_or_same_artifactID:some_version_x.y.z@ext_if_any'

}

We have multiple such entries in the dependencies section for all the libraries that our app/service would need for running build/test/IT tests etc (at runtime).

Gradle works good so far and downloads all the artifacts from Artifactory.

I'm working on a project where I need to get all the versions of an artifact (what all is available in the dependencies section) for a single groupID:artifactID only) i.e. I want the following .jar (default extension) and create a zip file containing all the versioned .jars in it:

compile 'my.company.com:cool_library:1.0.0'
compile 'my.company.com:cool_library:1.0.1'
compile 'my.company.com:cool_library:1.1.0'
compile 'my.company.com:cool_library:1.2.0'

runtime 'my.company.com:another_cool_library:1.0.0'
runtime 'my.company.com:another_cool_library:1.2.0'
runtime 'my.company.com:cool_library:1.0.1'

I know how to create a .zip file in Gradle (it's easy) but Gradle is NOT getting/downloading all the .jar (for every version as I have listed above) from Artifactory or from a given binary repository system.

It only gets the latest one (i.e. cool_service-1.2.0.jar). Gradle does this nice because, this way you won't have duplicate class in the class path coming from the same project (cool_library) and due it its different versions mentioned in the dependencies section.

One would say, why I would need OLDER versions when the latest/greatest code is there in version 1.2.0 of cool_library and if a project which is consuming this library wants it, just say I want my.company.com:cool_library:1.2.0 and be done with it or get whatever single version you want for compiling. In my case, DEV team have written application code in a way that they define cool_library-1.0.0.jar here, but cool_library-1.2.0.jar somewhere else. Basically, I need all what a Developer has defined in the build.gradle file.

How can I create a custom_zip.zip file which will have all the cool_library-x.y.z.jar files that I have mentioned in dependencies section for "compile" heading.

Thanks.

解决方案

Using this great tool, it's possible. Read it all (for different ways to do things).

Link Gradle Download Task: https://github.com/michel-kraemer/gradle-download-task

For ex: In your build.gradle you'll have this:

plugins {
    id "de.undercouch.download" version "1.2"
}

import de.undercouch.gradle.tasks.download.Download
apply plugin: 'java'
apply plugin: 'de.undercouch.download'


repositories {
  maven {
    url "http://yourartifatory:1020/artifactory/virtual-repos"
  }
}

//Lets says, I want to download my.company.com:CoolServices:1.0 jar or any extension file
//Then I can create a list and specify what all I need as:
def deps = [
            [ "my/company/com", "CoolServices", "1.0", "jar" ],
            [ "my/company/com", "CoolServices", "1.1", "jar" ],
            [ "my/company/com", "CoolServices", "1.2", "jar" ]
           ]

task downloadArts << {
     //Iterate over each dependencies as per the list
     deps.each { groupId, artifactId, version, extn ->
          download {
              src "http://yourartifactory.fqdn.com:1020/artifactory/simple/some-physical-actual-repository-local/$groupId/$artifactId/$version/$artifactId-$version.$extn"
              dest buildDir
              //If you want the downloaded files inside build/xxx folder, create that xxx folder first outside of the clousure i.e. file("build/xxx").mkdir()
          }
     }
}


Now, run "gradle clean downloadArts" and it'll print what it's going to download / line and inside either build or build/xxx folder where you'll find all of your downloaded files (.jar/etc extensioned files that you mentioned in the deps list variable).

You can also use it to push into dependencies section for compile, runtime, testRuntime OR create a custom_zip.zip file if required.

For ex:

dependencies {
    compile  fileTree( dir: "build", include: '*.*' )
    runtime  fileTree( dir: "build/xxx", include: '*.*' )
}

Or create a custom_zip.zip file (containing all the downloaded .jar/extension files in it).

这篇关于Gradle - 从Artifactory下载单个groupID的所有版本jar:artifactID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆