如何使用gradle将Artifactory中的工件从项目类路径中提取出来?

时间:2013-10-16 16:27:40

标签: java groovy gradle artifactory

我是gradle和Artifactory集成的新手,到目前为止,我可以将工件从一个工作区发布到另一个工作区。

我所做的是创建了一个gradle示例项目,现在我想将JUnit jar发布到Artifactory中,然后将其作为依赖项检索到我的项目类路径,以便我可以运行我的项目。

项目结构

enter image description here

的build.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'
        }
    }
}

2 个答案:

答案 0 :(得分:7)

如果您只想从artifactory获取资源,可以保留所有从artifactory获得的build.gradle代码,然后输入:

repositories {
    maven {
        url 'http://artifactory.domain/artifactory/libs-release'
    }
}

此方法假定您对您的神器具有匿名读取权限。否则,您还需要创建包含以下内容的gradle.properties文件:

HOST=localhost
REALM=Artifactory Realm
USER=admin
PASSWORD=password

答案 1 :(得分:0)

您应该使用Artifactory plugin for Gradle。它既可以发布也可以检索爆炸,既可以作为常春藤工件也可以作为Maven工件。