11

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

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

项目结构

在此处输入图像描述

构建.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'
        }
    }
}
4

2 回答 2

12

如果您只对从 artifactory 获取资源感兴趣,则可以保留从 artifactory 获得的所有 build.gradle-code,然后输入:

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

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

HOST=localhost
REALM=Artifactory Realm
USER=admin
PASSWORD=password
于 2014-03-25T14:24:02.890 回答
0

你应该只使用Gradle 的 Artifactory 插件。它使发布和检索都成为爆炸式增长,无论是作为 Ivy 工件和/或 Maven 工件。

于 2013-10-16T19:47:32.927 回答