Search code examples
gradleartifactory

Gradle Artifactory deploy fails when using generated gradle.properties


I have the following build.gradle file:

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()
}

And this gradle.properties file:

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

The build fails with the following error:

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

If we take a look at the printed username and password, we see this:

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

Gradle takes the properties values as literal strings instead of evaluating them. So the issue seems to be that the security object cannot be found, because if I replace the properties in build.gradle file with their values directly, the following error occurs:

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.

What am I doing wrong? The deploy works fine when using plaintext username and password, but I would like to use the auto-generated way of logging in (using an encrypted password).


Solution

  • It seems that gradle.properties should look like this:

    username=your_username
    password=blahblah
    

    We suppose that blahblah is your encrypted password.