使用生成的gradle.properties时,Gradle Artifactory部署失败

时间:2019-02-19 17:22:11

标签: gradle artifactory

我有以下build.gradle文件:

plugins {
    id 'java-gradle-plugin'
    id 'com.gradle.plugin-publish' version '0.10.1'
    id 'groovy'
    id 'maven-publish'
    id "com.jfrog.artifactory" version "4.9.1"
}

group = 'de.gafertp'
version = '2.0.0'

repositories {
    mavenCentral()
}

dependencies {
    compile 'net.sourceforge.plantuml:plantuml:1.2019.1'

    testCompile 'org.junit.jupiter:junit-jupiter-api:5.4.0'
    testCompile 'org.junit-pioneer:junit-pioneer:0.3.0'
    testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.4.0'
}

gradlePlugin {
    plugins {
        plantUmlPlugin {
            id = 'de.gafertp.plantuml'
            displayName = 'Gradle PlantUML Plugin'
            description = 'A very simple plugin to render PlantUML files. ' +
                    'Takes a set of diagram files together with desired output files / formats ' +
                    'and renders them with PlantUML (http://plantuml.com/).'
            implementationClass = 'de.gafertp.PlantUmlPlugin'
        }
    }
}

pluginBundle {
    website = 'https://github.com/codecholeric/gradle-plantuml-plugin'
    vcsUrl = 'https://github.com/codecholeric/gradle-plantuml-plugin'
    tags = ['plantuml']
}

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

artifactory {
    contextUrl = "${artifactory_contextUrl}"
    publish {
        repository {
            repoKey = 'gradle-dev-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            println "username=${artifactory_user}"
            println "password=${artifactory_password}"
            maven = true
        }
        defaults {
            publications('plantUmlPluginJar')
        }
    }
    resolve {
        repository {
            repoKey = 'gradle-dev'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            maven = true
        }
    }
}

test {
    useJUnitPlatform()
}

这个gradle.properties文件:

artifactory_user=${security.getCurrentUsername()}
artifactory_password=${security.getEncryptedPassword()!"blahblah"}
artifactory_contextUrl=http://localhost:8081/artifactory

构建因以下错误而失败:

Execution failed for task ':artifactoryDeploy'.
> java.io.IOException: Failed to deploy file. Status code: 401 Response message: Artifactory returned the following errors:
  Unauthorized Status code: 401

如果我们查看打印的用户名和密码,就会看到以下内容:

username=${security.getCurrentUsername()}
password=${security.getEncryptedPassword()!"blahblah"}

Gradle将属性值视为文字字符串,而不是对其求值。因此问题似乎是找不到security对象,因为如果我直接用其值替换build.gradle文件中的属性,则会发生以下错误:

A problem occurred evaluating root project 'gradle-plantuml-plugin'.
> Could not get unknown property 'security' for object of type org.jfrog.gradle.plugin.artifactory.dsl.DoubleDelegateWrapper.

我在做什么错?使用纯文本用户名和密码时,部署工作正常,但是我想使用自动生成的登录方式(使用加密密码)。

1 个答案:

答案 0 :(得分:0)

gradle.properties看起来应该像这样:

username=your_username
password=blahblah

我们假设blahblah是您的加密密码。