1

我有一个自定义任务来从服务器获取凭据:

task getToken {
    ext.token = // curl whatever
}

我想在出版物存储库的凭据块中使用此任务的输出,如下所示:

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

    repositories {
        maven {
            url = "https://somewhere.com/repo"

            credentials {
                username System.properties['user.name']
                password getToken.token
            }
        }
    }
}

但是,我不知道那里的凭据何时解决,显然该任务getToken需要事先完成。

我如何实现这一目标?

4

1 回答 1

1

这可以通过这里的插件实现:https ://plugins.gradle.org/plugin/pl.unity.lazy-credentials

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "gradle.plugin.pl.unity.gradle:lazy-credentials:1.2.1"
    }
}

apply plugin: "pl.unity.lazy-credentials"

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

    repositories {
        maven {
            url "https://somewhere.com/repo"
            lazyCredentials {
                username System.properties['user.name']
                password {
                    // some code here to request the token
                }
            }
        }
    }
}
于 2019-08-16T12:16:42.337 回答