Java 如何使用 gradle 从 Artifactory 中提取工件到项目类路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19408735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pull artifacts from Artifactory to project classpath using gradle?
提问by Simple-Solution
I'm new to gradle and Artifactory integration and so far I can publish artifacts from one workspace to another.
我是 gradle 和 Artifactory 集成的新手,到目前为止,我可以将工件从一个工作区发布到另一个工作区。
What I did was created a gradle sample project and now I would like to publish i.e. JUnit jar into Artifactory and then retrieve it to my project classpath as a dependency, so that I can run my project.
我所做的是创建了一个 gradle 示例项目,现在我想将 ie JUnit jar 发布到 Artifactory,然后将其作为依赖项检索到我的项目类路径,以便我可以运行我的项目。
Project strructure
项目结构
build.gradle
构建.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
//apply plugin: 'artifactory-publish'
sourceCompatibility = 1.5
version = '1.0'
jar
{
manifest
{
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation Version': version
}
}
buildscript
{
repositories
{
maven
{
url 'http://dl.bintray.com/jfrog/jfrog-jars'
}
mavenCentral()
}
dependencies
{
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.1.0')
}
}
//pull/retrieve artifacts(jar) from artifactory
repositories
{
ivy
{
url = 'http://localhost:8081/artifactory/APM-jars'
credentials
{
username = 'admin'
password = 'password'
}
}
mavenCentral()
dependencies {
compile group: 'jakarta-regexp', name: 'jakarta-regexp', version: '1.+'
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
}
test {
systemProperties 'property': 'value'
}
///publish/upload artifact (jar) into 3 different type of builds
uploadArchives
{
repositories
{
//Just copy to a directory
//flatDir
//{
//dirs 'repos2'
//}
//Publish to an Ivy repository in Artifactory.
ivy
{
url = 'http://localhost:8081/artifactory/test-ivy'
credentials
{
username = 'admin'
password = 'password'
}
}
//Publish to a Gradle repository in Artifactory.
ivy
{
url = 'http://localhost:8081/artifactory/test-gradle'
credentials
{
username = 'admin'
password = 'password'
}
//layout 'gradle'
layout 'pattern',
{
artifact '[module]/[revision]/[artifact](.[ext])'
ivy '[module]/[revision]/ivy.xml'
}
}
//Publish to a Maven repository in Artifactory.
ivy
{
url = 'http://[host]:port/artifactory/test-maven'
credentials
{
username = 'admin'
password = 'password'
}
layout 'maven'
}
}
}
采纳答案by javabeangrinder
If you are only interested in getting resources from artifactory you can leave all the build.gradle-code you get from artifactory and just enter:
如果您只对从 artifactory 获取资源感兴趣,您可以保留从 artifactory 获取的所有 build.gradle-code 并输入:
repositories {
maven {
url 'http://artifactory.domain/artifactory/libs-release'
}
}
This approach assumes you have anonymous read access to you artifactory. Otherwise you also need to create the gradle.properties file containing:
这种方法假设您对人工制品具有匿名读取权限。否则,您还需要创建 gradle.properties 文件,其中包含:
HOST=localhost
REALM=Artifactory Realm
USER=admin
PASSWORD=password
回答by JBaruch
You should just use Artifactory plugin for Gradle. It makes both publishing and retrieving a blast, both as Ivy artifacts and/or as Maven artifacts.
您应该只为 Gradle使用Artifactory 插件。无论是作为 Ivy 工件还是作为 Maven 工件,它都使发布和检索都大受欢迎。