【问题标题】:Fixing Gradle Artifactory plugin publishing issue修复 Gradle Artifactory 插件发布问题
【发布时间】:2015-02-27 18:13:11
【问题描述】:

我正在使用 Gradle 构建一个多项目构建:

myapp/
    myapp-client/
    myapp-shared/
    myapp-server/
    build.gradle
    settings.gradle

settings.gradle 的样子:

include ':myapp-shared'
include ':myapp-client'
include ':myapp-server'

我已成功让 Gradle 编译我的 Groovy 源代码、运行单元测试、生成 GroovyDocs,并为所有 3 个子项目打包二进制和源 JAR。其构建调用为:gradle clean build groovydoc sourcesJar -Pversion=<whatever version I specify>

我现在正在尝试添加 Gradle-Artifactory 插件,这样:

  • 所有 3 个子项目都会为它们生成 POM;和
  • 所有 3 个子项目二进制 JAR、POM 源 JAR 都发布到我在本地运行的 Artifactory;和
  • artifactoryPublish 任务在gradle build 被调用时执行

这是我最好的尝试(我的完整 build.gradle):

allprojects {
    buildscript {
        repositories {
            maven {
                url 'http://localhost:8081/artifactory/plugins-release'
                credentials {
                    username = "admin"
                    password = "password"
                }
                name = "maven-main-cache"
            }
        }
        dependencies {
            classpath "org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1"
        }
    }

    apply plugin: 'groovy'
    apply plugin: 'maven'
    apply plugin: 'maven-publish'
    apply plugin: "com.jfrog.artifactory"

    version="0.0.1"
    group = "mygroup"

    repositories {
        mavenCentral()
        add buildscript.repositories.getByName("maven-main-cache")
        maven {
            url "http://localhost:8081/artifactory/mydev-snapshots"
        }
    }

    artifactory {
        contextUrl = "http://localhost:8081/artifactory"
        publish {
            repository {
                repoKey = 'mydev-snapshots'
                username = "admin"
                password = "password"
                maven = true
            }
            defaults {
                publications ('mavenJava')
            }
        }
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                from components.java
            }
        }
    }
}

rootProject {
    artifactoryPublish.skip=true
}

subprojects {
    apply plugin: 'groovy'
    apply plugin: 'eclipse'

    sourceCompatibility = '1.7'
    targetCompatibility = '1.7'

    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

    repositories {
        mavenLocal()
        mavenCentral()
        maven {
            url "https://repository.apache.org/content/repositories/snapshots"
        }
        maven {
            url "http://localhost:8081/artifactory/mydev-snapshots"
        }
        maven {
            url "https://code.google.com/p/guava-libraries/"
        }
    }

    dependencies {
        compile (
            'org.codehaus.groovy:groovy-all:2.3.7'
        )
    }

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

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

    build(dependsOn: 'artifactoryPublish')
}

当我运行gradle clean build groovydoc sourcesJar -Pversion=0.1.1 时,我得到以下命令行异常:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\myuser\sandbox\eclipse\workspace\myapp\build.gradle' line: 14

* What went wrong:
A problem occurred evaluating root project 'myapp'.
> You can't change a configuration which is not in unresolved state!

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.589 secs

我的问题:这里发生了什么,我需要做什么(特别是)来修复它并发布 Artifactory 插件?

额外问题:我在 2 个位置指定版本号(构建调用以及 build.gradle 文件内。我想通过构建调用指定版本号如何配置artifactoryPublish(或者更确切地说,Gradle-Artifactory 插件)以接受我从命令行指定的版本?

【问题讨论】:

    标签: groovy gradle artifactory


    【解决方案1】:

    这里的问题数量:

    1. buildscript 应该是顶级块,而不是在 allprojects 内部
    2. 使用 Artifactory 时,不需要指定除 Artifactory 之外的任何其他存储库(不需要mavenCentral()
    3. 如果你想使用artifactoryPublish你需要配置Artifactory插件。 Here are the docs,这里有两个完整的多模块 Gradle 项目示例:12。一些亮点:
    4. 您需要申请mavenmaven-publish插件。
    5. 您需要相应地将生成的工件添加到configurationpublication
    6. 您需要使用您正在使用的 Artifactory 实例配置插件,提供解析和部署存储库名称、凭据(通常仅用于部署)并指定要发布的 configurationpublication

    【讨论】:

    • 多模块 Gradle 项目示例的链接不起作用 :-(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多