如何使用 Gradle 构建 Groovy JAR 并将其发布到内部存储库 [英] How to build Groovy JAR w/ Gradle and publish it to in-house repo

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

问题描述

我有一个 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.1myapp-1.2.2?我也不认为我的 publications 配置设置正确: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'
        }
    }
}

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

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