如何构建Groovy JAR w / Gradle并将其发布到内部回购站点 [英] How to build Groovy JAR w/ Gradle and publish it to in-house repo

查看:115
本文介绍了如何构建Groovy JAR w / Gradle并将其发布到内部回购站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Groovy项目,并试图用Gradle构建它。首先,我想要一个 package 任务,通过编译它的依赖关系来创建JAR。然后,我需要为该JAR生成Maven POM,并将JAR / POM发布到内部Artifactory回购。 build.gradle

I have a Groovy project and am trying to build it with Gradle. First I want a package task that creates a JAR by compiling it against its dependencies. Then I need to generate a Maven POM for that JAR and publish the JAR/POM to an in-house Artifactory repo. The build.gradle:

apply plugin: "groovy"
apply plugin: "maven-publish"

repositories {
    maven {
        name "artifactory01"
        url "http://myartifactory/artifactory/libs-release"
    }
}
dependencies {
    compile "long list starts here"
}

// Should compile up myapp-<version>.jar
jar {
}

// Should publish myapp-<version>.jar and its (generated) POM to our in-house Maven/Artifactory repo.
publishing {
    publications {
        myPublication(MavenPublication) {
            from components.java
            artifact sourceJar {
                classifier "source"
            }

            pom.withXml {
                // ???
            }
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

然而我不相信我已经正确地使用 jar 任务(例如,我怎么能创建 myapp-1.2.1 myapp-1.2.2 code>?我也不认为我的出版物配置正确设置:应该在 pom.withXml

However I do not believe I have set up versioning correctly with my jar task (for instance, how could I get it creating myapp-1.2.1 vs. myapp-1.2.2? I also don't think I have my publications configuration set up correctly: what should go in pom.withXml?

推荐答案

欢迎您使用 artifactory 插件。
文档可以在我们的用户指南和下面,你可以找到一个完整的Gradle构建示例。

You're more than welcome to use artifactory plugin for that. The documentation can be found in our user guide and below you can find a full working example of gradle build.

运行 gradle build artifactoryPublish 构建并发布项目。

Run gradle build artifactoryPublish to build and publish the project.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.0.1')
    }
}
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.artifactory'

group = 'com.jfrog.example'
version = '1.2-SNAPSHOT'
status = 'SNAPSHOT'

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.5'
    testCompile 'junit:junit:4.11'
}

task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

publishing {
    publications {
        main(MavenPublication) {
            from components.java
            artifact sourcesJar
    }
}

artifactory {
    contextUrl = 'http://myartifactory/artifactory'
    resolve {
        repository {
            repoKey = 'libs-release'
        }
    }
    publish {
        repository {
            repoKey = 'libs-snapshot-local'
            username = 'whatever'
            password = 'whatever123'
        }
        defaults {
            publications 'main'
        }
    }
}

这篇关于如何构建Groovy JAR w / Gradle并将其发布到内部回购站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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